Last active
April 9, 2018 14:52
-
-
Save rnaufal/6fa94f6321f08876436055bfab1956e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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