java8对list进行多字段去重(亲测可用)

List<CatTest> catList = Lists.newArrayList();
catList.stream()
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(cat -> cat.getCarHobby() + cat.getCatName()))),
ArrayList::new
)
);
posted @ 2021-08-06 09:42  十月围城小童鞋  阅读(1170)  评论(0编辑  收藏  举报