弄了好久搞不出来,大神帮看看,思路还有代码哪里有问题?
数组去重复,例如: 原始数组是{4,2,4,6,1,2,4,7,8},得到结果{4,2,6,1,7,8}
public class Test8 {
public static void main(String[] args) {
int[] arr = {4,2,4,6,1,2,4,7,8};
zhuanhuan( arr);
}
public static void zhuanhuan(int[] arr)
{
ArrayList list = new ArrayList();
ArrayList list1 = new ArrayList();
for(int x = 0;x < arr.length;x++)
{
list.add(arr[x]);
}
Iterator it = list.iterator();
while(it.hasNext())
{
if(!list1.contains(it.next()))
{
list1.add(it.next());
}
}
System.out.println(list);
System.out.println(list1);
}
} |
|