gistfile1.txt package day16.ArrayList;import java.util.ArrayList;import java.util.Iterator;/** * 描述: * ArrayList去除集合中自定义对象元素的重复值 * * @outhor 71948 * @create 2017-10-01 15:51 */public class Demo2_ArrayList
package day16.ArrayList; import java.util.ArrayList; import java.util.Iterator; /** * 描述: * ArrayList去除集合中自定义对象元素的重复值 * * @outhor 71948 * @create 2017-10-01 15:51 */ public class Demo2_ArrayList { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add(new Person("zhan",21)); list.add(new Person("zhan",21)); list.add(new Person("san",22)); list.add(new Person("san",22)); ArrayList newList = getSingel(list); System.out.println(newList); } public static ArrayList getSingel(ArrayList list){ ArrayList newList = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()){ Object obj = it.next(); if (!newList.contains(obj)){ newList.add(obj); } } return newList; } }