public static List removeDuplicateWithOrder(List list) {
Set set = new HashSet();
List newList = new ArrayList();
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object element = iter.next();
if (set.add(element)){
newList.add(element);
}
}
return newList;}
===========================
这样利用set去了重复,又用linked保持住了原顺序。
return
new
ArrayList<T>(
new
LinkedHashSet<T>(list));
========
public static List removeDuplicateWithOrder(List list) {
List newList = new ArrayList();
for (Object o : list) {
if (!newList .contains(o)) newList.add(o);
}
return newList;
}
=======
set.addAll(list);
=====
Set<Object> set = new HashSet<Object>(list);