Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map<List<String>, String> map = new HashMap<>();
map.put(List.of("A", "B"), "X");
map.put(List.of("C"), "Y");
var result = map.entrySet()
.stream()
.flatMap(kv -> kv.getKey().stream().map(k -> Map.entry(k, kv.getValue())))
.collect(Collectors.toMap(k -> k.getKey(), v -> v.getValue()));
result.entrySet().forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment