stream interface methods one liner description

41
Stream Interface methods one-liner description. -Bharat Savani.

Upload: bharat-savani

Post on 15-Jan-2017

59 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Stream interface methods one liner description

Stream Interface methods one-liner

description.-Bharat Savani.

Page 2: Stream interface methods one liner description

1. filterStream<T> filter(Predicate<? super T> predicate);

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

Page 3: Stream interface methods one liner description

2. map<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.

Page 4: Stream interface methods one liner description

3. mapToInt•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.

Page 5: Stream interface methods one liner description

4. mapToLong•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.

Page 6: Stream interface methods one liner description

5. mapToDouble•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.

Page 7: Stream interface methods one liner description

6. flatMap•<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.

Page 8: Stream interface methods one liner description

7. flatMapToInt•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.

Page 9: Stream interface methods one liner description

8. flatMapToLong•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.

Page 10: Stream interface methods one liner description

9. flatMapToDouble•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.

Page 11: Stream interface methods one liner description

10. distinct•Stream<T> distinct();

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

Page 12: Stream interface methods one liner description

11. sorted•Stream<T> sorted();

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

Page 13: Stream interface methods one liner description

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

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

Page 14: Stream interface methods one liner description

13. peek•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.

Page 15: Stream interface methods one liner description

14. limit•Stream<T> limit(long maxSize);

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

Page 16: Stream interface methods one liner description

15. skip•Stream<T> skip(long n);

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

Page 17: Stream interface methods one liner description

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

Performs action on every element of this stream.

Page 18: Stream interface methods one liner description

17. forEachOrdered•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.

Page 19: Stream interface methods one liner description

18. toArray•Object[] toArray();

Returns array containing elements of this stream.

Page 20: Stream interface methods one liner description

19. toArray•<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.

Page 21: Stream interface methods one liner description

20. reduce•T reduce(T identity, BinaryOperator<T> accumulator);

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

Page 22: Stream interface methods one liner description

21. reduce•Optional<T> reduce(BinaryOperator<T> accumulator);

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

Page 23: Stream interface methods one liner description

22. reduce•<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.

Page 24: Stream interface methods one liner description

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

Performs mutable reduction operation on elements of the stream.

Page 25: Stream interface methods one liner description

24. collect•<R, A> R collect(

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

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

Page 26: Stream interface methods one liner description

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

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

Page 27: Stream interface methods one liner description

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

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

Page 28: Stream interface methods one liner description

27. count•long count();

Returns count of elements in this stream.

Page 29: Stream interface methods one liner description

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

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

Page 30: Stream interface methods one liner description

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

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

Page 31: Stream interface methods one liner description

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

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

Page 32: Stream interface methods one liner description

31. findFirst•Optional<T> findFirst();

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

Page 33: Stream interface methods one liner description

32. findAny•Optional<T> findAny();

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

Page 34: Stream interface methods one liner description

33. builder•public static<T> Builder<T> builder()

Returns the builder for the stream.

Page 35: Stream interface methods one liner description

34. empty•public static<T> Stream<T> empty();

Returns the empty sequential stream.

Page 36: Stream interface methods one liner description

35. of•public static<T> Stream<T> of(T t)

Returns the sequential stream with single element.

Page 37: Stream interface methods one liner description

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

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

Page 38: Stream interface methods one liner description

37. iterate•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.

Page 39: Stream interface methods one liner description

38. generate•public static<T> Stream<T> generate(Supplier<T> s)

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

Page 40: Stream interface methods one liner description

39. concat•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.

Page 41: Stream interface methods one liner description

That’s all folks.