我有 BalancedetailList,其中我需要迭代和累积 Orginalvale,并将其与该列表中的每个债务值进行多次白化迭代进行比较。
BigDecimal cumulatetotamt= new BigDecimal(0);
BigDecimal thresholdRem= new BigDecimal(0);
第一次迭代
for (Balance bal : BalanceList) {
for (Adjustments adj: AdjustmentsReportList) {
if (adj.getminval().equals(bal.thresholdval())) {
cumulatetotamt= cumulatetotamt.add(bal.orginalval());
}
}
}
Second iteration
for (Balance bal : BalanceList) {
for (Adjustments adj: AdjustmentsReportList) {
thresholdRem= adj.val1().subtract(adj.val2())
if (cumulatetotamt.compareTo(thresholdRem) > 0){
}
}
}
如何使用 Stream l 使其成为单次迭代
第一次改成这样可行吗
BigDecimal totalBillAmt = BalanceList.stream()
.flatMap(bal -> AdjustmentsReportList.stream()
.filter(adj -> adj.getBillCode().equals(bal.getSellQuotaNo()))
.map(Bill::getBillAmt))
.reduce(BigDecimal.ZERO, BigDecimal::add);
第二次使用映射而不是循环?