import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Collections; import java.util.Set; public class test1 ... { /** *//** * @param args */ public static void main(String[] args) ...{ // TODO Auto-generated method stub test1 absolute=new test1(); } public test1() ...{ ArrayList<Integer> abc = new ArrayList<Integer>(); for (int i = 0; i < 10; i++) ...{ abc.add(i); } for (int i = 0; i < 10; i++) ...{ abc.add(i); } System.out.println("old:"+abc); removeDuplicateWithOrder(abc);// for(int m=0;m<abc.size();m++){// if(abc.contains(abc.get(m)))// abc.remove(m); // }// Collections.sort(abc);// for(int i=0;i<abc.size();i++){// System.out.print(" "+abc.indexOf(i));// }// System.out.println(); System.out.println("new"+abc); Iterator<Integer> itr = abc.listIterator(); while (itr.hasNext()) ...{ Object obj = itr.next(); System.out.print(" "+obj); } } /** *//** List order not maintained **/ public void removeDuplicate(ArrayList<Integer> arlList) ...{ HashSet<Integer> h = new HashSet<Integer>(arlList); arlList.clear(); arlList.addAll(h); } /** *//** List order maintained **/ public void removeDuplicateWithOrder(ArrayList arlList) ...{ Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = arlList.iterator(); iter.hasNext(); ) ...{ Object element = iter.next(); if (set.add(element)) newList.add(element); } arlList.clear(); arlList.addAll(newList); }} 最后呢,觉得还是第二个比较适合我!