The following table lists some of the commonly used stream operations, their types, and descriptions.
Operation | Type | Description |
---|---|---|
Distinct | Intermediate | Returns a stream consisting of the distinct elements of this stream. |
filter | Intermediate | Returns a stream consisting of the elements of this stream that match the specified predicate. |
flatMap | Intermediate | Returns a stream consisting of the results of applying the specified function to the elements of this stream. |
limit | Intermediate | Returns a stream consisting of the elements of this stream, truncated to be no longer than the specified size. |
map | Intermediate | Returns a stream consisting of the results of applying the specified function to the elements of this stream. |
peek | Intermediate | Returns a stream whose elements consist of this stream. It applies the specified action as it consumes elements of this stream. |
skip | Intermediate | Discards the first n elements of the stream and returns the remaining stream. If this stream contains fewer than n elements, an empty stream is returned. |
sorted | Intermediate | Returns a stream consisting of the elements of this stream, sorted according to natural order or the specified Comparator. |
allMatch | Terminal | Returns true if all elements in the stream match the specified predicate, false otherwise. Returns true if the stream is empty. |
anyMatch | Terminal | Returns true if any element in the stream matches the specified predicate, false otherwise. Returns false if the stream is empty. |
findAny | Terminal | Returns any element from the stream. An empty Optional object is for an empty stream. |
findFirst | Terminal | Returns the first element of the stream. For an ordered stream, it returns the first element in the encounter order; for an unordered stream, it returns any element. |
noneMatch | Terminal | Returns true if no elements in the stream match the specified predicate, false otherwise. Returns true if the stream is empty. |
forEach | Terminal | Applies an action for each element in the stream. |
reduce | Terminal | Applies a reduction operation to computes a single value from the stream. |