Skip to content

Instantly share code, notes, and snippets.

@akarnokd
Created June 14, 2022 13:09
Show Gist options
  • Save akarnokd/75e4604c2c25d135c45969bccf3bf54a to your computer and use it in GitHub Desktop.
Save akarnokd/75e4604c2c25d135c45969bccf3bf54a to your computer and use it in GitHub Desktop.
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