本帖最后由 痞子、蔚 于 2014-7-21 20:20 编辑
import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class ArrayListTest2
{
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(new Person("zhangsan01",20));
al.add(new Person("zhangsan02",21));
al.add(new Person("zhangsan03",23));
al.add(new Person("zhangsan02",21));
al.add(new Person("zhangsan01",20));
al=quChong(al);
sop(al);
}
public static ArrayList quChong(ArrayList al)
{
ArrayList a = new ArrayList();
Iterator it = al.iterator();
while(it.hasNext())
{
if(!a.contains(it.next()))
a.add(it.next());.//这地方报的这错误NoSuchElementException
}
return a;
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
|
|