Java 使用Stream处理List对象去重

JAVA学习网 2020-11-28 06:26:01
// 根据name去重
List<Person> unique = persons.stream().collect(
            Collectors.collectingAndThen(
                    Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new)
);

 

阅读(2126) 评论(0)