Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ListOfPairsJava9 {
public static void main(String[] args) {
final Map<String, List<String>> values = new HashMap<>();
values.put("a", Arrays.asList("1", "2", "3"));
values.put("b", Arrays.asList("4", "5", "6"));
values.put("c", Collections.singletonList("7"));
final List<Map.Entry<String, String>> result = values
.entrySet()
.stream()
.collect(ArrayList::new,
(pairs, entry) -> pairs.addAll(entry
.getValue()
.stream()
.map(value -> Map.entry(entry.getKey(), value))
.collect(Collectors.toList())),
List::addAll);
System.out.println("result = " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment