流去重

根据单个条件去重
list.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(
Comparator.comparing(Class::getParams)))
, ArrayList::new));

根据多条件去重
list.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(
Comparator.comparing(a->a.getParam1+";"+a.getParam2)))
, ArrayList::new));
posted @ 2021-08-03 16:06  DarkerbeS  阅读(87)  评论(0编辑  收藏  举报