stream根据某个字段去重
注意事项:如果是List的话,需要再重新new一个去接收过滤后的列表
如果是ArrayList的话,不需要重新new一个列表,因为它是可变的
List<AlarmExplanationModel> resNewList = resultList.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getGjContent()))), ArrayList::new));
参考链接:
Stream流根据对象的某个字段去重
Stream按对象某属性去重的方案