使用java8实现List中对象属性的去重
单个属性去重
ArrayList<BookInfoVo> distinctLiost = list.stream()
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparingLong(BookInfoVo::getRecordId))), ArrayList::new));
多个属性去重
ArrayList<BookInfoVo> distinctLiost = list.stream()
.collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
o -> o.getName() + ";" + o.getAuthor()))), ArrayList::new));


