Stream Storm / Part 1YOUTUBE PLAYER LOADS ON PLAYfilter, map, flatMap
filter+map+flatMap+sorted

Java Streams Explained Visually: filter, map, flatMap, sorted | Stream Storm Part 1

Stream Storm11 Oct 20261:21Open on YouTube

In this lesson

A stream sends each item through a few steps. filter keeps items that pass a test, map changes every item, flatMap unpacks lists inside a list, and sorted puts them in order. Nothing runs until you ask for a result.

The code from the video

java
List<Integer> numbers = List.of(3, 8, 1, 6, 5, 2);
 
List<Integer> result = numbers.stream()
    .filter(n -> n % 2 == 0)   // keep the even numbers
    .map(n -> n * 10)          // multiply each by ten
    .toList();
 
System.out.println(result);    // [80, 60, 20]

flatMap unpacks lists inside a list, and sorted puts the result in order:

java
List<List<Integer>> nested = List.of(List.of(3, 8), List.of(1), List.of(6, 5, 2));
 
nested.stream()
    .flatMap(List::stream)
    .sorted()
    .toList();                  // [1, 2, 3, 5, 6, 8]
The surprise: streams are lazy.

filter and map only make a plan. Nothing moves until a terminal step such as toList() asks for the result, and then each item goes through every step, one at a time.

Keep going

More Shorts.