//存在重复数据的问题,这里使用stream流的衍生功能,去除一个对象中的部分元素的重复如下:
ArrayList<Book> collect = list.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(
Book::getPrice))), ArrayList::new));
//多个字段或者多个条件去重
ArrayList<Book> collect1 = list.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(p->p.getName() + ";" + p.getPrice()))), ArrayList::new));
09-30
4034
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-30
916
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-08
701
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交