使用Stream流将List<BillExternalInfo> 按字段分组为Map<Long, List<Long>>
可以使用stream流的collect方法结合Collectors.groupingBy来实现根据某个字段将List
Map<Long, List<Long>> resultMap = externalInfos.stream()
.collect(Collectors.groupingBy(BillExternalInfo::getField,
Collectors.mapping(BillExternalInfo::getId, Collectors.toList())));
上述代码中,使用Collectors.groupingBy方法将List
原文地址: https://www.cveoy.top/t/topic/qjux 著作权归作者所有。请勿转载和采集!