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://*.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

上一篇:java并发学习第五章--线程中的锁


下一篇:asp.net mvc Htmlhelper简单扩展