list集合去重:
public List<WmsUserExcelVo> repetitionRepetition(List<WmsUserExcelVo> excelListl) {
List<WmsUserExcelVo> newList = excelListl.stream().distinct().collect(Collectors.toList());
return newList;
}
list集合根据某一个属性去重:
public List<WmsMemoryExcelVo> repetitionRepetitions(List<WmsMemoryExcelVo> excelListl) {
//对list数据 根据某个字段去掉重复数据 这里用的根据vin去除重复值,两个结果相同值去最后一条
List<WmsMemoryExcelVo> newList = excelListl.stream().collect(Collectors.collectingAndThen
(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing
(WmsMemoryExcelVo::getVin))), ArrayList::new));
return newList;
}
list集合查询重复值:
List<WmsMemoryExcelVo> list = gressionList.stream()
.collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b))
.entrySet().stream()
.filter(entry -> entry.getValue() > 1)
.map(entry -> entry.getKey())
.collect(Collectors.toList());