Streams Operations
Description
The commonly used stream operations are listed as follows.
- Distinct
Intermediate Operation
Returns a stream consisting of the distinct elements by checking equals() method. - filter
Intermediate Operation
Returns a stream that match the specified predicate. - flatMap
Intermediate Operation
Produces a stream flattened. - limit
Intermediate Operation
truncates a stream by number. - map
Intermediate Operation
Performs one-to-one mapping on the stream - peek
Intermediate Operation
Applies the action for debugging. - skip
Intermediate Operation
Discards the first n elements and returns the remaining stream. If this stream contains fewer than requested, an empty stream is returned. - sorted
Intermediate Operation
Sort a stream according to natural order or the specified Comparator. For an ordered stream, the sort is stable. - allMatch
Terminal Operation
Returns true if all elements in the stream match the specified predicate, false otherwise. Returns true if the stream is empty. - anyMatch
Terminal Operation
Returns true if any element in the stream matches the specified predicate, false otherwise. Returns false if the stream is empty. - findAny
Terminal Operation
Returns any element from the stream. Returns an empty Optional object for an empty stream. - findFirst
Terminal Operation
Returns the first element of the stream. For an ordered stream, it returns the first element; for an unordered stream, it returns any element. - noneMatch
Terminal Operation
Returns true if no elements in the stream match the specified predicate, false otherwise. Returns true if the stream is empty. - forEach
Terminal Operation
Applies an action for each element in the stream. - reduce
Terminal Operation
Applies a reduction operation to computes a single value from the stream.