0% found this document useful (0 votes)
3 views2 pages

Java Stream API Cheat Sheet

This cheat sheet provides an overview of Java Stream API methods, categorized into creation methods, intermediate operations, and terminal operations. It includes methods for filtering, mapping, sorting, collecting, matching, and reducing data. Additionally, it highlights specialized streams for primitive data types and their respective methods.

Uploaded by

diptesh2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Stream API Cheat Sheet

This cheat sheet provides an overview of Java Stream API methods, categorized into creation methods, intermediate operations, and terminal operations. It includes methods for filtering, mapping, sorting, collecting, matching, and reducing data. Additionally, it highlights specialized streams for primitive data types and their respective methods.

Uploaded by

diptesh2021
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Stream API - Methods Cheat Sheet

Creation Methods

- [Link](T... values): Create stream from values.

- [Link](array): Convert array to stream.

- [Link](): Create stream from collection.

- [Link](Supplier): Infinite stream using generator.

- [Link](seed, UnaryOperator): Infinite stream with iteration.

Intermediate Operations - Filtering & Matching

- filter(Predicate): Keep only matching elements.

- distinct(): Remove duplicates.

- limit(n): First n elements.

- skip(n): Skip first n elements.

Intermediate Operations - Mapping

- map(Function): Transform each element.

- mapToInt / mapToDouble / mapToLong: Convert to primitive streams.

Intermediate Operations - Flat Mapping & Sorting

- flatMap(Function): Flatten nested structures.

- sorted(): Natural order.

- sorted(Comparator): Custom sort.

- peek(Consumer): Debug or log values during stream processing.

Terminal Operations - Collecting

- collect([Link]()): Collect to list.

- collect([Link]()): Collect to set.

- collect([Link](", ")): Join strings.

- collect([Link](...)): Grouping.
Java Stream API - Methods Cheat Sheet

- collect([Link](...)): Partitioning.

Terminal Operations - Matching & Finding

- anyMatch(Predicate): Any match.

- allMatch(Predicate): All match.

- noneMatch(Predicate): None match.

- findFirst(): First element (Optional).

- findAny(): Any element (Optional).

Terminal Operations - Reducing & Aggregating

- count(): Count elements.

- reduce(identity, accumulator): Reduce to single value.

- min(Comparator): Smallest element.

- max(Comparator): Largest element.

Primitive Stream Specializations

- IntStream, LongStream, DoubleStream: Specialized streams.

- Methods: sum(), average(), min(), max(), range(), rangeClosed()

You might also like