java.util.stream · java.base · since Java 1.8

Stream

declaration
public interface Stream<T> extends BaseStream<T, Stream<T>>

A lazy pipeline of elements: intermediate operations (map/filter/flatMap) describe, one terminal operation (collect/reduce/count…) executes. Single-use; never mutates its source.

Key methods

Stream<R> map(Function<T,R>) / Stream<T> filter(Predicate<T>)The transform/select pair.
Stream<R> flatMap(Function<T, Stream<R>>)1→many + flatten.
Stream<T> sorted() / distinct() / limit(n) / skip(n)Stateful shapers.
Stream<T> takeWhile / dropWhile(Predicate<T>)Cut ordered streams at a condition (Java 9).
<R,A> R collect(Collector<T,A,R>)Mutable reduction — the main terminal.
Optional<T> reduce(BinaryOperator<T>) / T reduce(T, BinaryOperator<T>)Fold with an associative op.
boolean anyMatch/allMatch/noneMatch(Predicate<T>)Short-circuit predicates.
Optional<T> findFirst() / findAny()Short-circuit retrieval.
List<T> toList()Unmodifiable list (Java 16) — the everyday terminal.
static <T> Stream<T> of(T...) / iterate(seed, f) / generate(s)Sources.