import java.util.*;
class ArrayListDemo
{
public static void main(String[] args)
{
ArrayList al=new ArrayList();
al.add("java01");
al.add("java02");
al.add("java02");
al.add("java02");
al.add("java03");
al.add("java04");
al.add("java04");
System.out.println(al);
System.out.println(singleElement(al));
}
public static ArrayList singleElement(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;
}
}
【java编程】Collection类之ArrayList去除重复元素
最新推荐文章于 2023-06-13 18:18:08 发布