The full picture
🎬 Lazy stream pipeline with short-circuit
1 / 4stream().filter(n -> n % 2 == 0).map(n -> n * n).findFirst() — building the pipeline executes NOTHING. Intermediate ops are lazy; they just link stages together.
- Spliterator drives the source; each stage wraps the next stage's
Sink— a terminal op assembles the chain then pushes/pulls elements through it. - Stateless vs stateful ops:
map/filterfuse cleanly;sorted/distinctmust buffer (a barrier) — asorted()in the middle quietly makes 'lazy' mostly moot up to that point. - Single-use: a stream is a one-shot pipeline, not a data structure; reusing it throws
IllegalStateException. - Don't mutate the source mid-pipeline; interference is checked only best-effort.