import java.util.*;
public class acc
{
public static void main(String argv[])
{
ArrayList al=new ArrayList();
al.add("java1");
al.add("java2");
al.add("java2");
al.add("java3");
al.add("java4");
al.add("java4");
sop(al);
singleElements(al);
sop(al);
}
public static ArrayList singleElements(ArrayList al)
{
ArrayList newal=new ArrayList();
Iterator it =al.iterator();
while(it.hasNext())
{
Object obj=it.next();
if(!newal.contains(obj))
newal.add(obj);
}
return newal;
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
结果:[java1, java2, java2, java3, java4, java4]
[java1, java2, java2, java3, java4, java4]
目的是把从父元素去掉,但是跟原来一样,问题出在哪呢?
目的是把重复的元素去掉, |
|