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
This should work. Please notice that you lost some keys from List.
Map> mapFrom = new HashMap<>();
Map mapTo = mapFrom.entrySet().stream()
.flatMap(integerListEntry -> integerListEntry.getValue()
.stream()
.map(listItem -> new AbstractMap.SimpleEntry<>(listItem, integerListEntry.getKey())))
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));