Assuming I have a Map<Integer, Map<Class, String>>
how could I get all combinations of the Integer
keys of the outer map and the keys of all maps which are values of outer map in one elegant (but probably long) Java stream declaration?
My approaches:
Map<Integer, Map<Class, String>> map = new HashMap<>();
map.keySet().stream()
.map(intKey -> map.get(intKey).keySet().stream()
.map(classKey -> new SimpleEntry(intKey, classKey)))
.collect(Collectors.toList());
collects a list of java.util.stream.ReferencePipeline
. With
map.keySet().stream()
.map(intKey -> map.get(intKey).keySet().stream()
.map(classKey -> new SimpleEntry(intKey, classKey))
.collect(Collectors.toList()))
.collect(Collectors.toList());
I have trouble wrapping my head around the collection of already collected SimpleEntry
s. Of course, the approach can be wrong completely.
My problems is that I simply don't find a way to solve this. Please note that I'm not looking for a workaround as I want to broaden my understanding.