public List<String> removeStringListDupli(List<String> stringList) {
Set<String> set = new LinkedHashSet<>();
set.addAll(stringList);
stringList.clear();
stringList.addAll(set);
return stringList;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
或使用Java8的写法:
List<String> unique = list.stream().distinct().collect(Collectors.toList());
- 1
- 1
可以参见:http://*.com/questions/30745048/how-to-remove-duplicate-objects-from-java-arraylist
http://blog.csdn.net/growing_tree/article/details/46622579
http://www.cnblogs.com/jizha/p/java_arraylist_duplicate.html
http://*.com/questions/29670116/remove-duplicates-from-a-list-of-objects-based-on-property-in-java-8