stream api筆記

1.分組求和

Map<CxFeeAmountType, BigDecimal> feeMap = feeBills.stream()
                .filter(receipt -> receipt.getWithtaxAmount() != null)
                .collect(Collectors.groupingBy(CxFeeAmountType::getType,
                        Collectors.reducing(BigDecimal.ZERO, CxFeeBillDTO::getWithtaxAmount, BigDecimal::add)));
複製代碼

由於會報空指針異常,因此最好先過濾掉爲null的數據.bash

相關文章
相關標籤/搜索