Java Stream: Convert Map<String, List<ScoreItemTableSourceVO>> to Map<String, Map<String, List<ScoreItemTableSourceVO>>>
You can use Java 8's Stream to transform a 'Map<String, List
Here's an example code:
Map<String, Map<String, List<ScoreItemTableSourceVO>>> transformedMap = assesseeIdKeyMap.entrySet()
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().stream()
.collect(Collectors.groupingBy(ScoreItemTableSourceVO::getPropertyName))
));
In the code above, we use 'entrySet().stream()' to convert 'assesseeIdKeyMap' into a stream. Then, we use the 'Collectors.toMap()' method to map each item in the stream to a new item. The key remains the original String key, while the value is a new Map. The new Map is created by the inner stream and 'Collectors.groupingBy()' method. We use 'ScoreItemTableSourceVO::getPropertyName' as the grouping criteria, grouping 'ScoreItemTableSourceVO' objects by the 'propertyName' property.
This way, you obtain a 'transformedMap' of type 'Map<String, Map<String, List
原文地址: https://www.cveoy.top/t/topic/qxCi 著作权归作者所有。请勿转载和采集!