gistfile1.txt package day16.ArrayList;import java.util.ArrayList;import java.util.Iterator;/** * 描述: * ArrayList去除从重复元素的应用 * * @outhor 71948 * @create 2017-10-01 15:39 */public class Demo1_ArrayList_New { public stat
package day16.ArrayList; import java.util.ArrayList; import java.util.Iterator; /** * 描述: * ArrayList去除从重复元素的应用 * * @outhor 71948 * @create 2017-10-01 15:39 */ public class Demo1_ArrayList_New { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add("a"); list.add("a"); list.add("b"); list.add("b"); ArrayList newList = getSingle(list); System.out.println(newList); } public static ArrayList getSingle(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; } }