Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active December 18, 2015 15:09
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 codeaholicguy/5f3db089e225f7be6d5c to your computer and use it in GitHub Desktop.
Save codeaholicguy/5f3db089e225f7be6d5c to your computer and use it in GitHub Desktop.
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