使用stream去重List对象集合
不墨迹,代码如下:
单属性:
List<Course> arrayList = courseThirds.stream().collect(
Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing( Course::getBjmc))),ArrayList::new));
多属性:
List<Course> arrayList = courses.stream().collect(
Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(
o -> o.getKcmc() + ";" + o.getJsbh() + ";"
+ o.getZc() + ";" + o.getXq() + ";" + o.getJc())
)), ArrayList::new));