最近工作中需要在有重复数据的数据表中查出数据集合并且不能重复,但由于数据量太大就不好用group by分组,这里用一次Stream的去重操作
oldSegments.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(o ->
o.getDptTime() + ";" + o.getArrTime() + ";" + o.getDate() + ";" + o.getDptAirport() + ";" + o.getArrAirport() + ";" + o.getFlightCode()))), ArrayList::new));
这样看的更简洁
dishList.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Dish::getId))), ArrayList::new));