Terminal Stream Operations and reduce in Java
A terminal operation runs the pipeline and produces a result, and reduce is the general purpose way to fold a stream into one value.
Notes related to the Java language.
100 notes tagged
A terminal operation runs the pipeline and produces a result, and reduce is the general purpose way to fold a stream into one value.
filter, map, flatMap, sorted, distinct, limit, skip and peek. Each returns a new stream and none of them runs on its own.
A stream describes a computation over a sequence of elements. You state what you want, and the pipeline decides how to walk the data.
Optional makes absence part of the type, so a caller cannot forget that a value might not be there.
When a lambda does nothing but call an existing method, a method reference says the same thing with less noise.
An interface with exactly one abstract method can be implemented by a lambda, and the standard library supplies the ones you need most.
A lambda is a short way to write an implementation of a single method interface, so behaviour can be passed around like a value.
Generic type information exists only at compile time. Knowing what the compiler removes explains every generics restriction.
Bounds restrict what a type parameter may be, and wildcards let a method accept a family of parameterised types safely.
Generics let a class or method work with a type supplied by the caller, moving whole families of errors from runtime to compile time.
The helper methods that save writing loops, and a practical way to pick the right collection every time.
Comparable gives a class one natural order. Comparator supplies any number of orders from outside, without touching the class.