//分组统计 Map<String,BigDecimal> firmAndNum=new HashMap<>(); Map<String,IntSummaryStatistics> masp=projectPostList.stream().filter(s->s.getPeopleCounting()!=null&& s.getPeopleCounting()!=0 &&s.getFirmName()!=null && !"".endsWith(s.getFirmName())).collect(Collectors.groupingBy(ProjectPost::getFirmName,Collectors.summarizingInt(ProjectPost::getPeopleCounting))); for (Map.Entry<String,IntSummaryStatistics> mapsc: masp.entrySet()) { firmAndNum.put(mapsc.getKey(),BigDecimal.valueOf(mapsc.getValue().getSum())); } //list全部统计 //当被统计的字段不是想要的类型时 Integer re=projectPostList.stream().mapToInt(ProjectPost::getPeopleCounting).sum(); //不需要类型转换 List<Integer> num = projectPostList.stream().map(ProjectPost::getPeopleCounting).collect(Collectors.toList()); Integer a = num.stream().reduce(Integer::sum).orElse(0);
List分组求和
最新推荐文章于 2022-06-11 11:00:41 发布