Skip to content

Instantly share code, notes, and snippets.

@Barakat
Created July 20, 2015 01:13
Show Gist options
  • Save Barakat/7bf957367e1dce97b128 to your computer and use it in GitHub Desktop.
Save Barakat/7bf957367e1dce97b128 to your computer and use it in GitHub Desktop.
Java Stream#flatMap minimal example.
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<List<Integer>> nested = Arrays.asList(
Arrays.asList(1, 2, 3),
Arrays.asList(4, 5, 6),
Arrays.asList(7, 8, 9)
);
nested.forEach(System.out::println);
nested.stream()
.flatMap(Collection::stream)
.forEach(System.out::println);
}
}
@Barakat
Copy link
Author

Barakat commented Jul 20, 2015

Output:

[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
1
2
3
4
5
6
7
8
9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment