Person类
// 根据name去重
List<Person> unique = persons.stream().collect( Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new) );
这样会留下一个唯一姓名的,就比如原来List中有三个张三,会留下一个name = 张三的。用的是TreeSet集合保存。
原文:https://www.cnblogs.com/onlyzhangmeng/p/13494782.html