1 回答

TA貢獻(xiàn)1845條經(jīng)驗 獲得超8個贊
添加合并功能。例如:
Map<String, List<Fee>> feeAccountMap = ContractList
.stream()
.filter(o -> !o.getStatus().equals(ContractStatus.CLOSED))
.collect(Collectors.toMap(o -> o.getFeeAccount(), o -> {
List<Fee> monthlyFees;
try {
monthlyFees = contractFeeService.getContractMonthlyFees(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
return monthlyFees;
}, (value1, value2) -> value1
));
由于您的值Map似乎是鍵的函數(shù),因此當(dāng)您有兩個具有相同鍵的值時,您可以簡單地返回其中一個值。
這是假設(shè)如果 的兩個元素ContractList返回相同的Stringfor getFeeAccount(),則它們彼此相等。
添加回答
舉報