Skip to content

Instantly share code, notes, and snippets.

@fge
Created December 20, 2014 14:16
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 fge/2cc1379ddbb88ce35c9b to your computer and use it in GitHub Desktop.
Save fge/2cc1379ddbb88ce35c9b to your computer and use it in GitHub Desktop.
public static void main(String[] args)
{
final Map<String, List<String>> map = new HashMap<>();
map.put("foo", Arrays.asList("bar", "baz"));
map.put("foo2", Arrays.asList("bar2", "baz2"));
map.entrySet().stream().flatMap(e -> {
final Stream.Builder<Map.Entry<String, String>> builder
= Stream.builder();
final String k = e.getKey();
e.getValue().stream().forEach(v -> builder.accept(new AbstractMap
.SimpleEntry<>(k, v)));
return builder.build();
}).forEach(System.out::println);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment