List<Map<String,Object>> risk = new ArrayList<>();
List<String> ids = new ArrayList<>();
riskAddrCount.stream().filter(x -> null !=x ).forEach(x ->{
if(risk.size()==0){
risk.add(x);
ids.add(x.get("tid").toString());
}else {
if(!ids.contains(x.get("tid").toString())){
risk.add(x);
ids.add(x.get("tid").toString());
}else{
risk.stream().filter(m -> null !=m &&
m.get("tid").toString().equals(x.get("tid").toString())).forEach(m ->{
m.put("riskCount",Integer.parseInt(m.get("riskCount").toString())+Integer.parseInt(m.get("riskCount").toString()));
});
}
}
});
使用java 8的steam实现list集合 map中去除重复项并且某一项相加
最新推荐文章于 2024-09-09 17:45:12 发布