I would like to flatten a Map which associates an Integer key to a list of String, without losing the key mapping. I am curious as tho
Map
Integer
String
You should use flatMap as follows:
flatMap
entrySet.stream() .flatMap(e -> e.getValue().stream() .map(s -> new SimpleImmutableEntry(e.getKey(), s)));
SimpleImmutableEntry is a nested class in AbstractMap.
SimpleImmutableEntry
AbstractMap