Creating Streams
• stream(): Creates a sequential stream from a collection.
• parallelStream(): Creates a parallel stream from a
collection.
Intermediate Operations
• filter(Predicate<T> predicate): Filters elements based
on a predicate.
• map(Function<T, R> mapper): Transforms elements
using a given function.
• flatMap(Function<T, Stream<R>>): Transforms
elements into streams and then flattens them into a single
stream.
• distinct(): Removes duplicate elements from the stream.
• sorted(): Sorts the elements in natural order.
• sorted(Comparator<T> comparator): Sorts the
elements using a provided comparator.
• limit(long maxSize): Truncates the stream to contain no
more than the specified number of elements.
• skip(long n): Skips the first n elements of the stream.
• peek(Consumer<T> action): Performs the provided
action on each element of the stream and returns a new
stream with the same elements.
• mapToInt(ToIntFunction<T> mapper): Transforms
elements into an IntStream.
• mapToDouble(ToDoubleFunction<T> mapper):
Transforms elements into a DoubleStream.
• mapToLong(ToLongFunction<T> mapper):
Transforms elements into a LongStream.
• flatMapToInt(Function<T, IntStream> mapper):
Transforms elements into an IntStream and flattens them.
• flatMapToDouble(Function<T, DoubleStream>
mapper): Transforms elements into a DoubleStream and
flattens them.
• flatMapToLong(Function<T, LongStream> mapper):
Transforms elements into a LongStream and flattens
them.
• boxed(): Converts a primitive stream (like IntStream,
DoubleStream, LongStream) into a stream of their
wrapper objects (like Stream<Integer>,
Stream<Double>, Stream<Long>).
• takeWhile(Predicate<T> predicate): Takes elements
while the given predicate is true and stops as soon as the
predicate is false.
• dropWhile(Predicate<T> predicate): Drops elements
while the given predicate is true and starts taking
elements as soon as the predicate is false.
Terminal Operations
• forEach(Consumer<T> action): Performs an action for
each element of the stream.
• collect(Collector<T, A, R> collector): Collects the
elements of the stream into a collection.
• reduce(BinaryOperator<T> accumulator): Performs a
reduction on the elements using an associative
accumulation function.
• reduce(T identity, BinaryOperator<T> accumulator):
Performs a reduction on the elements with an initial
value.
• toArray(): Returns an array containing the elements of
the stream.
• anyMatch(Predicate<T> predicate): Returns true if
any elements match the provided predicate.
• allMatch(Predicate<T> predicate): Returns true if all
elements match the provided predicate.
• noneMatch(Predicate<T> predicate): Returns true if
no elements match the provided predicate.
• findFirst(): Returns the first element of the stream, if
present.
• findAny(): Returns any element of the stream, useful in
parallel streams.
• count(): Returns the count of elements in the stream.
• max(Comparator<T> comparator): Returns the
maximum element of the stream according to the
provided comparator.
• min(Comparator<T> comparator): Returns the
minimum element of the stream according to the
provided comparator.