Map<String, List<Test>> map=new HashMap<>();
Map<String, List<Test>> map1= mapHandlerFilter(map,"9");
public Map<String, List<EndingComputeDTO>> mapHandlerFilter(Map<String, List<EndingComputeDTO>> map, String filters) {
if (map == null) {
return null;
} else {
map = map.entrySet().stream()
.filter((e) ->e.getKey().contains(filters))
.collect(Collectors.toMap(
(e) -> (String) e.getKey(),
Map.Entry::getValue
));
}
return map;
}
对map集合计算总数
计算map的value中,EndingComputeDTO对象的OriginalQuantity属性,进行值的汇总
Map<String, List<EndingComputeDTO>> map1=new HashMap<>();
Map<String,Double> stringDoubleMap= map1.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,e ->e.getValue().stream().mapToDouble(EndingComputeDTO::getOriginalQuantity).sum()));
网友评论