使用方式如下:
//定义集合
List<PrescriptionDTO> entryValue = entry.getValue();
//1.int类型求和
int successCount = entryValue.stream().mapToInt(PrescriptionDTO::getSuccessCount).sum();
//2.当数据有为空的,数据处理
BigDecimal sum = entryValue.stream().map(PrescriptionDTO::getMoney).
filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
函数拆解分析:
1. map(PrescriptionDTO::getMoney) ----获取集合里对象的指定字段
2. filter(Objects::nonNull) ----只获取money字段非空的对象
3. reduce(BigDecimal.ZERO, BigDecimal::add) ----对money字段进行求和