- package com.hei;
- import java.util.ArrayList;
- import java.util.Iterator;
- public class De_LianXi {
- public static void main(String[] args){
- ArrayList<Person> list = new ArrayList<>();
- list.add(new Person("张三",23));
- list.add(new Person("lisi",24));
- list.add(new Person("lisi",24));
- list.add(new Person("lisi",24));
- list.add(new Person("wangwu",25));
- ArrayList newList = getNew(list);
- System.out.println(newList);
-
- }
- public static ArrayList getNew(ArrayList list){
- ArrayList newList = new ArrayList();
- Iterator<Person> it = list.iterator();
- while(it.hasNext()){
- Object o = it.next();
- if(!newList.contains(o)){
- newList.add(o);
- }
- }
-
-
- return newList;
-
-
- }
-
- }
复制代码 |
|