Skip to content

Instantly share code, notes, and snippets.

@rnaufal
Last active April 9, 2018 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnaufal/6fa94f6321f08876436055bfab1956e6 to your computer and use it in GitHub Desktop.
Save rnaufal/6fa94f6321f08876436055bfab1956e6 to your computer and use it in GitHub Desktop.
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