要求一个表中的多条数据,根据id过滤,重复数据只取第一条
###hashset
### List<Object> collect = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new)).get(0)
去重并且取第一条
###list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getId()))), ArrayList::new))
楼上答主可能理解错意思了,只需要这样就可以了,默认取的是第一条