Java8 List字符串 去重

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://stackoverflow.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://stackoverflow.com/questions/29670116/remove-duplicates-from-a-list-of-objects-based-on-property-in-java-8

posted @ 2017-08-10 14:55  托马斯布莱克  阅读(3673)  评论(0编辑  收藏  举报