作者:mobiledu2502883017 | 来源:互联网 | 2022-11-18 15:07
如何在没有副作用的情况下添加/添加eServiceReportsMapByBatchFile
键?oldReportId
eServiceReportMap
Map>> eServiceReportMap = new HashMap<>();
reports.forEach(report -> {
String oldReportId = report.getOldId();
Map> eServiceReportsMapByBatchFile = // processing of batch files
...
eServiceReportMap.put(oldReportId, eServiceReportsMapByBatchFile);
});
return eServiceReportMap;
也就是说,我希望它变成这样:
return reports.stream()
.map(report -> {
String oldReportId = report.getOldId();
Map> eServiceReportsMapByBatchFile = // processing of batch files
...
// I don't know how and what to return here
}).collect(// I don't know what to do here);
谢谢.
1> Naman..:
你期待的主要是Collectors.toMap
可以用作:
return reports.stream()
.collect(Collectors.toMap(report -> report.getOldId(),
report -> {
// batch processing for eServiceReportsMapByBatchFile
return eServiceReportsMapByBatchFile;
}));