jdk1.8 stream 求和

BigDecimal:
BigDecimal bb =list.stream().map(Plan::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
 

int、double、long:

double max = list.stream().mapToDouble(User::getHeight).sum();

BigDecimal promoTotalMoney = goodsInfoList.stream().filter(g -> g.isPromoFlag()).map(item -> BigDecimal.valueOf(item.getGoodsPrice()).multiply(BigDecimal.valueOf(item.getGoodsCnt()))).reduce(BigDecimal.ZERO, BigDecimal::add);

posted @ 2020-04-26 11:46  暗渡陈仓xy  阅读(3961)  评论(0编辑  收藏  举报