Introduction to the Stream API in Java
A stream describes a computation over a sequence of elements. You state what you want, and the pipeline decides how to walk the data.
Building streams, intermediate and terminal operations, collectors.
5 notes
A stream describes a computation over a sequence of elements. You state what you want, and the pipeline decides how to walk the data.
filter, map, flatMap, sorted, distinct, limit, skip and peek. Each returns a new stream and none of them runs on its own.
A terminal operation runs the pipeline and produces a result, and reduce is the general purpose way to fold a stream into one value.
Collectors turn a stream into a collection, a map or a summary, and grouping is where they become genuinely powerful.
A parallel stream splits the work across threads. It helps less often than people expect, and it breaks silently when the rules are ignored.