package com.heima.zuoye;
import java.lang.reflect.Array;
import java.security.acl.Permission;
import java.util.ArrayList;
import java.util.Iterator;
import com.heima.bean.Person;
public class Demo1_ArrayList {
public static void main(String[] args) {
ArrayList list = new ArrayList<>();
list.add(new Person("张三", 23));
list.add(new Person("张三", 23));
list.add(new Person("张三", 23));
list.add(new Person("李四", 24));
list.add(new Person("李四", 24));
list.add(new Person("李四", 24));
ArrayList newlist = getSingle(list);
System.out.println(newlist);
}
public static ArrayList getSingle(ArrayList list) {
ArrayList newlist = new ArrayList();
Iterator i = list.iterator();
while(i.hasNext()) {
Object o = i.next();
if (!newlist.contains(o)) {
newlist.add(o);
}
}
return newlist;
}
}
|
|