The 30 second answer
Intermediate operations do nothing until a terminal operation runs. Then elements are pulled through the fused pipeline one at a time, not stage by stage. That is why short-circuiting and infinite streams work, and why a peek alone prints nothing until you add a terminal call.
Intermediate ops do nothing until a terminal op runs; then elements are pulled through the fused pipeline one at a time (vertical, not stage-by-stage). That allows short-circuiting and infinite streams:
Stream.iterate(1, i -> i + 1).filter(i -> i % 2 == 0).limit(5)Demo: Stream.of(1, 2, 3).peek(System.out::println) alone prints nothing.
Sources:
Sources (0)
See inline citations in the answer above.