return new ArrayList(new HashSet(list));
1.循环元素删除 ArrayList中重复元素
public static void removeDuplicate(List list) {
for ( int i = 0 ; i < list.size() - 1 ; i ++ ) {
for ( int j = list.size() - 1 ; j > i; j -- ) {
if (list.get(j).equals(list.get(i))) {
list.remove(j);
}
}
}
System.out.println(list);
}
2.通过 HashSet剔除 ArrayList中重复元素
public static void removeDuplicate(List list) {
HashSet h = new HashSet(list);
list.clear();
list.addAll(h);
System.out.println(list);
}
3. 删除ArrayList中重复元素,保持顺序