根据多个字段去重:
List distinctData = dtoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o ->
o.getType() + “;” + o.getRegistNo() + “;” +
o.getRegistrantName() + “;” + o.getName() + “;” +
o.getProductNameCn() + “;” + o.getApprovalDate() + “;” +
o.getExpireDate()))), ArrayList::new));
List collectList1 = query.getInfoList().stream().map(MainVO::getReceiverId).collect(Collectors.toList());
List collectList2 = actList.stream().map(v -> v.getId()).collect(Collectors.toList());
List dtoList = actList.stream().map(v -> {
testDto dto = new testDto();
dto.setId(v.getId());
dto.setTagId(v.getTagId());
dto.setTagName(v.getCreatedBy());
dto.setUserId(v.getUserId());
return dto;
}).collect(Collectors.toList());
//list转map
Map<String, List> testMap = new HashMap<>();
testMap = dtoList.stream().collect(Collectors.groupingBy(testDto::getId));
testVOMap = testVOList.stream().collect(Collectors.toMap(testVO::getId, a -> a,(k1,k2)->k1));
testVO::getId 表示testVO中的getId 代表map的key
a -> a 表示原先的对象作为现在map的value
(k1,k2)->k1 表示当k1和k2值相同时 取k1
//去重
List areaList = areaPOList.stream().map(areaDetailPO::getAreaName).distinct().collect(Collectors.toList());
Map<String,String> Map1 =
resList.stream().collect(Collectors.toMap(k->
k.getCompanyName()+k.getProductName()+k.getOtherCompanyName()+k.getHospitalName()+k.getProductClassify()+k.getFileCode()+k.getStartTime()+k.getEndTime(), h->
h.getStartTime()+“;”+h.getCompanyName()+“;”+h.getOtherCompanyName()+“;”+h.getProductClassify()+“;”+h.getFileCode()+“;”+h.getEndTime(),(oldValue, newValue) -> newValue));
List List11 = resList.stream().map(k->
k.getStartTime()+“;”+k.getCompanyName()+“;”+k.getOtherCompanyName()+“;”+k.getProductClassify()+“;”+k.getFileCode()+“;”+k.getEndTime()).distinct().collect(Collectors.toList());
List List12 = resList.stream().map(k->
k.getCompanyName()+“;”+k.getProductLineName()+“;”+k.getOtherCompanyName()+“;”+k.getProductClassify()+k.getFileCode()).collect(Collectors.toList());
map1:
公司1产品线公司2产品分类文件编号2021-10-012022-11-30 -> 2021-10-01;公司1;公司2;产品线;文件编号;2022-11-30
List11:
2021-10-01;公司1;公司2;产品线;文件编号;2002-11-30
List12:
公司1;产品线;公司2;产品线文件编号
根据相同字段分组
mainVOList.stream().collect(Collectors.groupingBy(ScOutSockRecordMainVO::getAuthItemId));
参考:
https://blog.csdn.net/weixin_45476233/article/details/120989215