Stream Interface’s methods one-liner description

1. filter(Predicate)

Stream<T> filter(Predicate<? super T> predicate);

Returns a stream consisting of elements of this stream which matches the given Predicate.

2. map(Function)

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

Returns a stream consisting of elements that are results of function applied on given elements.

3. mapToInt(ToIntFunction)

IntStream mapToInt(ToIntFunction<? super T> mapper);

Returns a int stream or primitive stream consisting of elements that are results of function applied on given elements.

4. mapToLong(ToLongFunction)

LongStream mapToLong(ToLongFunction<? super T> mapper);

Returns a map stream or primitive stream consisting of elements that are results of function applied on given elements.

5. mapToDouble(ToDoubleFunction)

DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper);

Returns a double stream or primitive stream consisting of elements that are results of function applied on given elements.

6. flatMap(Function)

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

Returns a stream consisting of results of replacing each element of this stream with the contents of mapped stream produced by applying the provided mapping function to each element.

7. flatMapToInt(Function)

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

Returns a int stream i.e. primitive stream consisting of results of replacing each element of this stream with the contents of mapped stream produced by applying the provided mapping function to each element.

8. flatMapToLong(Function)

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

Returns a long stream i.e. primitive stream consisting of results of replacing each element of this stream with the contents of mapped stream produced by applying the provided mapping function to each element.

9. flatMapToDouble(Function)

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

Returns a long stream i.e. primitive stream consisting of results of replacing each element of this stream with the contents of mapped stream produced by applying the provided mapping function to each element.

10. distinct()

Stream<T> distinct();

Returns the stream consisting of distinct elements according to Object#equals(Object).

11. sorted()

Stream<T> sorted();

Returns a stream consisting of elements of this stream sorted according to natural order.

12. sorted(Comparator)

Stream<T> sorted(Comparator<? super T> comparator);

Returns a stream consisting of elements of this stream sorted according to Comparator.

13. peek(Consumer)

Stream<T> peek(Consumer<? super T> action);

Returns a stream consisting of elements of this stream additionally performing the provided action on each element as elements are consumed from resulting stream.

14. limit(long)

Stream<T> limit(long maxSize);

Returns a stream consisting of elements no longer than max size.

15. skip(long)

Stream<T> skip(long n);

Returns a stream consisting of remaining elements of this stream after discarding first n elements of stream.

16. forEach(Consumer)

void forEach(Consumer<? super T> action);

Performs action on every element of this stream.

17. forEachOrdered(Consumer)

void forEachOrdered(Consumer<? super T> action);

Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined order.

18. toArray()

Object[] toArray();

Returns array containing elements of this stream.

19. toArray(IntFunction)

<A> A[] toArray(IntFunction<A[]> generator);

Returns an array containing the elements of this stream using the provided generator function to allocate the returned array.

20. reduce(T, BinaryOperator)

T reduce(T identity, BinaryOperator<T> accumulator);

Performs the reduction on elements of stream using provided identity and accumulator. Returns the reduced value.

21. reduce(BinaryOperator)

Optional<T> reduce(BinaryOperator<T> accumulator);

Performs the reduction on elements of stream using provided accumulator. Returns the reduced value.

22. reduce(U, BiFunction, BinaryOperator)

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

Performs the reduction on elements of stream using provided identity, accumulator and combiner.

23. collect(Supplier, BiConsumer, BiConsumer)

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

Performs mutable reduction operation on elements of the stream.

24. collect(Collector)

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

Performs mutable reduction operation on elements of the stream using Collector.

25. min(Comparator)

Optional<T> min(Comparator<? super T> comparator);

Returns the min element from the stream based on this comparator.

26. max(Comparator)

Optional<T> max(Comparator<? super T> comparator);

Returns the max element from the stream based on this comparator.

27. count()

long count();

Returns count of elements in this stream.

28. anyMatch(Predicate)

boolean anyMatch(Predicate<? super T> predicate);

Returns true if any element in stream matches this predicate. Returns false otherwise.

29. allMatch(Predicate)

boolean allMatch(Predicate<? super T> predicate);

Returns true if all elements in stream matches this predicate. Returns false otherwise.

30. noneMatch(Predicate)

boolean noneMatch(Predicate<? super T> predicate);

Returns true if none elements in stream matches this predicate. Returns false otherwise.

31. findFirst()

Optional<T> findFirst();

Returns first element from the stream. This method is normally used with filter method.

32. findAny()

Optional<T> findAny();

Returns some element from the stream. This method is normally used with filter method.

33. builder()

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

Returns the builder for the stream.

34. empty()

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

Returns the empty sequential stream.

35. of(T)

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

Returns the sequential stream with single element.

36. of(T…)

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

Returns the sequential ordered stream whose elements are specified in var-args.

37. iterate(T, UnaryOperator)

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

Returns an infinite sequential ordered stream produced by function f to initial element seed producing stream of seed, f(seed), f(f(seed)), and so on.

38. generate(Supplier)

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

Returns an infinite sequential stream where each element are provided by supplier.

39. concat(Stream, Stream)

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

Returns a stream where elements of first stream are concatenated to elements of second stream.

Leave a Reply

Your email address will not be published. Required fields are marked *