Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy

codeaholicguy/flatMap.java

Last active Dec 18, 2015
Embed
What would you like to do?
List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
List<Integer> list2 = Arrays.asList(2, 4, 6);
List<Integer> list3 = Arrays.asList(3, 5, 7);
List<List<Integer>> list = Arrays.asList(list1, list2, list3);
// Output [[1, 2, 3, 4, 5, 6, 7], [2, 4, 6], [3, 5, 7]]
System.out.println(list);
Function<List<Integer>, Stream<Integer>> flatMapper = l -> l.stream();
// Output 1 2 3 4 5 6 7 2 4 6 3 5 7
list.stream().flatMap(flatMapper).forEach(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.