I need to get the values in the inner most map as a list in Map<String, List<Map<String,Map<String,String>>>>
.
Other than for each, Can we implement it using streams?
Stream#flatMap returns a Stream of all values of all elements:
List<String> converted = yourComplexStructure.values().stream()
.flatMap(List::stream)
.map(Map::values)
.flatMap(Collection::stream())
.map(Map::values)
.flatMap(Collection::stream()))
.collect(Collectors.toList());
It takes the values of your structure as a Stream, maps it to a Stream with all elements of each List, maps it to a Stream with all values of the Maps, creates a Stream with all values of the most inner maps and collects it.
Note that it is basically the same as the other answer (we wrote it at the same time) but I changed this answer so that it doesn't require lambdas but uses method references.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments