java8利用lambda表达式对map集合进行分组求和,求最大值,平均值

List resultList = new ArrayList();
//对结果集进行分组求和
Map> resultMap = resultList.stream().collect(Collectors.groupingBy(undueReverseRepo ->
   undueReverseRepo.getMarketCode() +"#"+ undueReverseRepo.getFundcode() +"#"+ undueReverseRepo.getFundname() +"#"+ undueReverseRepo.getSettlcurramt2()
));
List result = new ArrayList<>();
resultMap.forEach((k, kList) ->{
    UndueReverseRepoData nmap = new UndueReverseRepoData();
    DoubleSummaryStatistics sumcc = kList.stream().collect(Collectors.summarizingDouble(e->Double.valueOf(e.getAmt())));
    nmap.setMarketCode(kList.get(0).getMarketCode());
    nmap.setFundcode(kList.get(0).getFundcode());
    nmap.setFundname(kList.get(0).getFundname());
    nmap.setAmt(String.valueOf(sumcc.getSum()));
    nmap.setSettlcurramt2(kList.get(0).getSettlcurramt2());
    if(new BigDecimal(String.valueOf(nmap.getSettlcurramt2())).compareTo(new BigDecimal(String.valueOf(nmap.getAmt()))) > 0){
        result.add(nmap);
    }
});

参考:https://www.cnblogs.com/JasonKong/articles/11174554.html

你可能感兴趣的:(java)