Java

Module 4: Stream API – Core Concepts

By Utility Zone · 2026-01-27T18:41:39.493134

Target Audience

  • Java developers new to Streams
  • Developers comfortable with Lambdas and Method References
  • Anyone preparing for real-world Java 8 data processing

1. Objective of This Module

By the end of this module, you will:

  • Understand what Streams are
  • Learn how Streams differ from Collections
  • Understand the Stream pipeline
  • Learn intermediate vs terminal operations
  • Grasp lazy evaluation

2. What Is a Stream?

A Stream is:

  • A sequence of elements
  • Supporting functional-style operations
  • Processed declaratively, not imperatively

👉 A Stream does not store data.
👉 It processes data from a source (Collection, Array, IO, etc.).


3. Stream vs Collection

AspectCollectionStream
StorageStores dataDoes not store data
IterationExternalInternal
ReusabilityCan be reusedCannot be reused
ExecutionImmediateLazy

4. Creating Streams

From a Collection

List<String> list = List.of("A", "B", "C");
Stream<String> stream = list.stream();

From Values

Stream<Integer> numbers = Stream.of(1, 2, 3);

From Arrays

Stream<String> stream = Arrays.stream(array);

5. Stream Pipeline

A Stream pipeline consists of:

  1. Source
  2. Intermediate operations
  3. Terminal operation
list.stream()
    .filter(s -> s.startsWith("A"))
    .map(String::toUpperCase)
    .forEach(System.out::println);

Nothing happens until the terminal operation is called.


6. Intermediate Operations

  • Return a Stream
  • Are lazy
  • Can be chained

Examples:

  • filter
  • map
  • flatMap
  • sorted
  • distinct

7. Terminal Operations

  • Trigger stream execution
  • Produce a result or side effect

Examples:

  • forEach
  • collect
  • count
  • findFirst
  • anyMatch

8. Lazy Evaluation

Streams use lazy evaluation:

  • Intermediate operations are not executed immediately
  • Execution starts only with a terminal operation
  • Operations run element-by-element

9. Stateless vs Stateful Operations

Stateless

  • map, filter

Stateful

  • sorted, distinct

10. Single-Use Streams

Streams cannot be reused.


11. Hands-On Exercises

  • Filter names starting with a letter
  • Identify stream pipeline parts
  • Predict output before execution

12. Summary

  • Streams are lazy
  • They process data, not store it
  • Correct understanding prevents misuse

13. What’s Next?

➡️ Phase 2 – Core Skills ➡️ Module 5: Stream API – Practical Operations