Streams API in Java

From the Java cheat sheet · Streams & Optional · verified Jul 2026

Streams API

Transform and aggregate collections functionally.

java
// Quick Reference
list.stream()
    .filter(x -> x > 2)
    .map(x -> x * 10)
    .toList();
💡 Streams are lazy - nothing runs until a terminal operation like toList() or count().
⚡ .toList() (Java 16+) is the concise replacement for .collect(Collectors.toList()).
📌 Use mapToInt/mapToDouble for numeric streams with sum(), average(), and range helpers.
🟢 A stream is single-use; create a fresh one for each pipeline you run.
streamsfunctional

Continue with Java

Save the full cheat sheet or work through every related task.

More Java tasks

Back to the full Java cheat sheet