Back to Lessons

Java Streams API

April 5, 2026

Streams API

Process collections functionally with intermediate/terminal operations.

Stream Pipeline

List numbers = Arrays.asList(1, 2, 3, 4, 5);

List evenSquares = numbers.stream()
    .filter(n -> n % 2 == 0)
    .map(n -> n * n)
    .collect(Collectors.toList());

// Output: [4, 16]

Key Points

  • Intermediate: filter(), map(), sorted().
  • Terminal: collect(), forEach(), reduce().
  • Parallel streams: parallelStream().
  • Lazy evaluation, no intermediate storage.