ArrayList<Person> list = new ArrayList<>();
list.add(new Person("bili", 27));
list.add(new Person("ak", 26));
list.add(new Person("as", 25));
list.add(new Person("ad", 24));
list.add(new Person("aj", 23));
list.add(new Person("bili", 27));
ArrayList<Person> newlist = new ArrayList<>();
Iterator<Person> it = list.iterator();
while(it.hasNext()){
Person p = it.next();
if(!newlist.contains(p)){
newlist.add(p);
}
}
list.clear();
newlist.addAll(list);
System.out.println(newlist);
}
|