JAVA8新特性lambda表达式(优雅的去重)

2019-07-27  本文已影响0人  不见当年三月花
字符串去重
List<String> dataList = list.stream().distinct().collect(Collectors.toList());

对象属性去重
//根据getName去重
personList = personList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                () -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new));

上一篇 下一篇

猜你喜欢

热点阅读