Java 8 Stream API - All Important Methods Guide
This PDF contains the most important Stream API methods used in Java 8 with short explanations and examples.
Stream Creation Methods
Method Description
stream() Creates a stream from collection
parallelStream() Creates a parallel stream
[Link]() Creates stream from values
[Link]() Creates stream from array
Intermediate Operations
Method Description
filter() Filters elements based on condition
map() Transforms each element
flatMap() Flattens nested structures
distinct() Removes duplicates
sorted() Sorts elements
peek() Performs debugging action
limit() Limits number of elements
skip() Skips elements
mapToInt() Converts object stream to IntStream
mapToLong() Converts object stream to LongStream
mapToDouble() Converts object stream to DoubleStream
mapToObj() Converts primitive stream to object stream
Terminal Operations
Method Description
forEach() Performs action on each element
collect() Collects result into List/Set/Map
count() Counts elements
findFirst() Returns first element
findAny() Returns any element
reduce() Reduces elements to single value
min() Finds minimum element
max() Finds maximum element
anyMatch() Checks if any element matches
allMatch() Checks if all elements match
noneMatch() Checks if no elements match
toArray() Converts stream to array
Collectors Utility Methods
Method Description
toList() Collects into List
toSet() Collects into Set
joining() Joins strings
counting() Counts elements
groupingBy() Groups elements
partitioningBy() Partitions into true/false groups
mapping() Applies mapping in collector
collectingAndThen() Performs extra operation after collect
summingInt() Calculates integer sum
averagingInt() Calculates average
summarizingInt() Provides statistics summary
maxBy() Finds max using collector
minBy() Finds min using collector
Common Stream API Examples
Filter Even Numbers
[Link]().filter(n -> n % 2 == 0).forEach([Link]::println);
Map Example
[Link]().map(n -> n * n).forEach([Link]::println);
Distinct Example
[Link]().distinct().forEach([Link]::println);
Collect Example
[Link]().collect([Link]());
Reduce Example
[Link]().reduce(0, (a,b) -> a+b);