将数组中相同的元素消去
思路:
1.创建一个新的ArrayList集合
2.遍历原始数组中的所有元素
3.新创集合调用contains方法,如果包含则不进行任何操作;不包含则使用add方法添加元素
//调用此方法,传入一个集合,集合中数据存储类型为Integer类型
public static ArrayList<Integer> removeElement(ArrayList<Integer> array1){
ArrayList array2 = new ArrayList();
Iterator iterator = array1.iterator();
while (iterator.hasNext()){
int next = (int)iterator.next();
if (!(array2.contains(next))){
array2.add(next);
}
}
return array2;
}