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()