SupportWriter space ↗
← Back to the journal
Java

Understanding Java Streams: Process Collections More Concisely

Learn how filter, map, and collect help you process Java data with readable code.

DPutu Adi Guna Permana · 16 Sep 2026 · 1 min read

You are reading a translated version.

From a collection to a data pipeline

Streams describe data transformations as a series of small steps. For example, an application stores participants' scores and needs to display those that meet the passing threshold.

import java.util.List;

public class Main {
    public static void main(String[] args) {
        var scores = List.of(62, 85, 71, 93);
        var passed = scores.stream()
            .filter(score -> score >= 75)
            .map(score -> "Lulus: " + score)
            .toList();
        passed.forEach(System.out::println);
    }
}

This example uses Java 17 or later. Its output is Lulus: 85 and Lulus: 93; the original example uses the Indonesian word for “passed.”

Why does the order matter?

filter selects elements that satisfy the condition. Next, map converts each number into text. The toList operation completes the pipeline and produces a new list; the original collection remains unchanged.

Keep in mind

A stream can only be consumed once. Create another stream from the collection if you need additional processing. Avoid modifying variables outside the lambda so the pipeline remains easy to understand.

Try it yourself

Change the passing threshold to 70, then add sorted() before map to order the results from the lowest score.

← Explore more notes