Java Streams Fundamentals
Fast recall
Quick revision
Core answer
Whether you understand a stream as a lazy, single-use pipeline (source → intermediate → terminal) and can explain laziness, fusion, and why side effects break it.
Confusing a Stream with a collection ('it stores data'), or adding side effects (mutating outside) in a forEach, missing that streams are lazy and single-use.
Define a stream as a lazy, single-use pipeline of source→intermediate→terminal, explain that intermediate ops are lazy and fused, and that side effects in lambdas break the model — then name when parallelStream helps and when it hurts.
Interview-ready guide
Interview answer
Java Streams are a declarative API for processing collections through a pipeline — a source, intermediate operations like filter and map, and a terminal operation like collect or reduce — and they exist because the imperative for-loop style is verbose and hard to parallelize.
The mental model I stress is that a stream is a lazy, single-use pipeline, not a data structure: it stores nothing. The intermediate operations are lazy — nothing executes until a terminal operation runs — and they're fused, so filter and map run as a single pass with no intermediate collection. A stream is consumed once; reusing it after a terminal throws an IllegalStateException.
The bugs I see most are side effects — people mutating external state in a forEach instead of using collect — and parallelStream, which people reach for thinking it's free parallelism, but it only helps for large, CPU-bound, stateless pipelines; for small or I/O-bound work its ForkJoinPool overhead and contention make it slower or non-deterministic.
Java Streams Fundamentals
Direct Answer
Java Streams (java.util.stream) is a declarative API for processing sequences of elements through a pipeline of operations — source, intermediate operations (filter, map, sorted), and a terminal operation (collect, reduce, forEach). They exist because the imperative for-loop way to transform, filter, and aggregate collections is verbose, error-prone, and hard to parallelize; a stream pipeline expresses the what (the computation) and lets the library handle the how (iteration, fusion, and even parallelism via parallelStream).
Common Mistakes & Pitfalls
Confusing a Stream with a collection ('it stores data'), or adding side effects (mutating outside) in a forEach, missing that streams are lazy and single-use.
Check your understanding
Answer these without looking back at the article.
- Why are stream intermediate operations lazy, and how does fusion make filter+map a single pass?
- Why can't a Stream be reused after a terminal operation, and what error do you get?
- When does parallelStream make code slower rather than faster, and why?
- Why is mutating external state in forEach a bug, and what should you use instead?
- What is the difference between a stateful (sorted) and stateless (filter) intermediate operation?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.