日期:2014-05-20  浏览次数:20657 次

删除数组中的元素
RT
我要删除一个数组中的元素,该怎么做。比如:
int a[] = {0,1,2,3,4,5,6,7,8,9} ;
int b[] = {3,5,1} ;
我要将a中包含b的元素删除。就是把3,5,1分别删除。应该怎么做,求大神指点。拜谢

------解决方案--------------------

public static void removeArrayDemo() {
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int b[] = { 3, 5, 1 };
List<Integer> aList = new ArrayList<Integer>();
List<Integer> bList = new ArrayList<Integer>();
for (int i : a) {
aList.add(i);
}
for (int i : b) {
bList.add(i);
}
aList.removeAll(bList);
System.out.println(aList);
}

转成集合类利用集合类的操作就行