Java8 List字符串 去重

   
   
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
public List<String> removeStringListDupli(List<String> stringList) {Set<String> set = new LinkedHashSet<>();set.addAll(stringList);stringList.clear();stringList.addAll(set);return stringList;}

或使用Java8的寫法:java

   
   
   
   
  • 1
  • 1
List<String> unique = list.stream().distinct().collect(Collectors.toList());

能夠參見:http://stackoverflow.com/questions/30745048/how-to-remove-duplicate-objects-from-java-arraylist 
http://blog.csdn.net/growing_tree/article/details/46622579post

http://www.cnblogs.com/jizha/p/java_arraylist_duplicate.htmlspa

http://stackoverflow.com/questions/29670116/remove-duplicates-from-a-list-of-objects-based-on-property-in-java-8.net

相關文章
相關標籤/搜索