Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public interface Stream<T>

ExtendsAutoCloseable, BaseStream<T, Stream<T>>

A stream here is sequential and lazy: each stage pulls one element at a time from the one before it, and only when a terminal operation asks. So an infinite iterate or generate behind a limit ends, findFirst and the anyMatch family stop at the element that decides them, and the side effects of peek happen element by element, in encounter order.

What is not here: spliterators, and with them parallel evaluation. parallel() answers the stream it was called on.

Nested types

interface Stream.Builderjava.util.stream.Stream.Builder: collects elements, then answers them as a stream, once.

Methods

public abstract Stream<T> filter(Predicate<? super T> predicate)
public abstract <R> Stream<R> map(Function<? super T, ? extends R> mapper)
public abstract IntStream mapToInt(ToIntFunction<? super T> mapper)
public abstract LongStream mapToLong(ToLongFunction<? super T> mapper)
public abstract DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)
public abstract <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper)
public abstract IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper)
public abstract LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper)
public abstract DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper)
public abstract Stream<T> distinct()
public abstract Stream<T> sorted()
public abstract Stream<T> sorted(Comparator<? super T> comparator)
public abstract Stream<T> peek(Consumer<? super T> action)
public abstract Stream<T> limit(long maxSize)
public abstract Stream<T> skip(long n)
public abstract Stream<T> takeWhile(Predicate<? super T> predicate)
public abstract Stream<T> dropWhile(Predicate<? super T> predicate)
public abstract void forEach(Consumer<? super T> action)
public abstract void forEachOrdered(Consumer<? super T> action)
public abstract Object[] toArray()
public abstract <A> A[] toArray(IntFunction<A[]> generator)
public abstract T reduce(T identity, BinaryOperator<T> accumulator)
public abstract Optional<T> reduce(BinaryOperator<T> accumulator)
public abstract <U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner)
public abstract <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner)
public abstract <R, A> R collect(Collector<? super T, A, R> collector)
public default List<T> toList()An unmodifiable list of the elements, which may be null.
public abstract Optional<T> min(Comparator<? super T> comparator)
public abstract Optional<T> max(Comparator<? super T> comparator)
public abstract long count()
public abstract boolean anyMatch(Predicate<? super T> predicate)
public abstract boolean allMatch(Predicate<? super T> predicate)
public abstract boolean noneMatch(Predicate<? super T> predicate)
public abstract Optional<T> findFirst()
public abstract Optional<T> findAny()
public static <T> Stream.Builder<T> builder()
public static <T> Stream<T> empty()
public static <T> Stream<T> of(T t)
public static <T> Stream<T> ofNullable(T t)
public static <T> Stream<T> of(T... values)
public static <T> Stream<T> iterate(T seed, UnaryOperator<T> f)
public static <T> Stream<T> iterate(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)
public static <T> Stream<T> generate(Supplier<? extends T> s)
public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)

Inherited methods

Method details

filter

public abstract Stream<T> filter(Predicate<? super T> predicate)

map

public abstract <R> Stream<R> map(Function<? super T, ? extends R> mapper)

mapToInt

public abstract IntStream mapToInt(ToIntFunction<? super T> mapper)

mapToLong

public abstract LongStream mapToLong(ToLongFunction<? super T> mapper)

mapToDouble

public abstract DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper)

flatMap

public abstract <R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper)

flatMapToInt

public abstract IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper)

flatMapToLong

public abstract LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper)

flatMapToDouble

public abstract DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper)

distinct

public abstract Stream<T> distinct()

sorted

public abstract Stream<T> sorted()

sorted

public abstract Stream<T> sorted(Comparator<? super T> comparator)

peek

public abstract Stream<T> peek(Consumer<? super T> action)

limit

public abstract Stream<T> limit(long maxSize)

skip

public abstract Stream<T> skip(long n)

takeWhile

public abstract Stream<T> takeWhile(Predicate<? super T> predicate)

dropWhile

public abstract Stream<T> dropWhile(Predicate<? super T> predicate)

forEach

public abstract void forEach(Consumer<? super T> action)

forEachOrdered

public abstract void forEachOrdered(Consumer<? super T> action)

toArray

public abstract Object[] toArray()

toArray

public abstract <A> A[] toArray(IntFunction<A[]> generator)

reduce

public abstract T reduce(T identity, BinaryOperator<T> accumulator)

reduce

public abstract Optional<T> reduce(BinaryOperator<T> accumulator)

reduce

public abstract <U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner)

collect

public abstract <R> R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner)

collect

public abstract <R, A> R collect(Collector<? super T, A, R> collector)

toList

public default List<T> toList()
An unmodifiable list of the elements, which may be null.

min

public abstract Optional<T> min(Comparator<? super T> comparator)

max

public abstract Optional<T> max(Comparator<? super T> comparator)

count

public abstract long count()

anyMatch

public abstract boolean anyMatch(Predicate<? super T> predicate)

allMatch

public abstract boolean allMatch(Predicate<? super T> predicate)

noneMatch

public abstract boolean noneMatch(Predicate<? super T> predicate)

findFirst

public abstract Optional<T> findFirst()

findAny

public abstract Optional<T> findAny()

builder

public static <T> Stream.Builder<T> builder()

empty

public static <T> Stream<T> empty()

of

public static <T> Stream<T> of(T t)

ofNullable

public static <T> Stream<T> ofNullable(T t)

of

public static <T> Stream<T> of(T... values)

iterate

public static <T> Stream<T> iterate(T seed, UnaryOperator<T> f)

iterate

public static <T> Stream<T> iterate(T seed, Predicate<? super T> hasNext, UnaryOperator<T> next)

generate

public static <T> Stream<T> generate(Supplier<? extends T> s)

concat

public static <T> Stream<T> concat(Stream<? extends T> a, Stream<? extends T> b)