Class Stream
java.lang.Object
org.apache.el.stream.Stream
A stream of elements supporting sequential operations such as filter, map,
reduce, and various terminal operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionChecks if all elements in the stream match the given predicate.Checks if any element in the stream matches the given predicate.average()Calculates the average of all numeric elements in the stream.count()Counts the number of elements in the stream.distinct()Returns a stream consisting of the distinct elements of this stream.Returns a stream consisting of the elements that match the given predicate.Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.Returns a stream consisting of the results of replacing each element of this stream with the contents of a stream produced by applying the provided function to each element.Performs an action for each element of this stream.Iterator<?> iterator()Returns the underlying iterator for this stream.Returns a stream consisting of the firstcountelements of this stream.map(LambdaExpression le) Returns a stream consisting of the results of applying the given function to the elements of this stream.max()Returns the maximum element of this stream according to natural order.max(LambdaExpression le) Returns the maximum element of this stream according to the provided comparator.min()Returns the minimum element of this stream according to natural order.min(LambdaExpression le) Returns the minimum element of this stream according to the provided comparator.Checks if no elements of this stream match the given predicate.peek(LambdaExpression le) Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed.Performs a reduction on the elements of this stream, using the provided accumulator function.reduce(Object seed, LambdaExpression le) Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.sorted()Returns a stream consisting of the elements of this stream, sorted according to natural order.Returns a stream consisting of the elements of this stream, sorted according to the order induced by the provided comparator.Returns a stream consisting of the elements of this stream from the specified start position to the end.Returns a stream consisting of the elements of this stream from the specified start position up to, but not including, the specified end position.sum()Returns the sum of all numeric elements in the stream.Object[]toArray()Returns an array containing all the elements of this stream.toList()Returns a list containing all the elements of this stream.
-
Constructor Details
-
Stream
-
-
Method Details
-
filter
Returns a stream consisting of the elements that match the given predicate.- Parameters:
le- the predicate to apply to each element- Returns:
- the new filtered stream
-
map
Returns a stream consisting of the results of applying the given function to the elements of this stream.- Parameters:
le- the function to apply to each element- Returns:
- the new mapped stream
-
flatMap
Returns a stream consisting of the results of replacing each element of this stream with the contents of a stream produced by applying the provided function to each element.- Parameters:
le- the function to apply to each element which produces a new stream- Returns:
- the new flattened stream
-
distinct
Returns a stream consisting of the distinct elements of this stream.- Returns:
- the new stream with distinct elements
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to natural order.- Returns:
- the new sorted stream
-
sorted
Returns a stream consisting of the elements of this stream, sorted according to the order induced by the provided comparator.- Parameters:
le- the comparator to determine sort order- Returns:
- the new sorted stream
-
forEach
Performs an action for each element of this stream.- Parameters:
le- the action to perform for each element- Returns:
- null
-
peek
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed.- Parameters:
le- the action to perform on each element- Returns:
- the new stream
-
iterator
Returns the underlying iterator for this stream.- Returns:
- the underlying iterator
-
limit
-
substream
-
substream
Returns a stream consisting of the elements of this stream from the specified start position up to, but not including, the specified end position.- Parameters:
start- the start position (inclusive)end- the end position (exclusive)- Returns:
- the new substream
-
toList
-
toArray
Returns an array containing all the elements of this stream.- Returns:
- the array of elements
-
reduce
Performs a reduction on the elements of this stream, using the provided accumulator function. The first element is used as the initial value.- Parameters:
le- the accumulator function- Returns:
- an Optional describing the reduced value, or empty if this stream is empty
-
reduce
Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.- Parameters:
seed- the initial value for the reductionle- the accumulator function- Returns:
- the result of the reduction
-
max
Returns the maximum element of this stream according to natural order.- Returns:
- an Optional describing the maximum element, or empty if this stream is empty
-
max
Returns the maximum element of this stream according to the provided comparator.- Parameters:
le- the comparator to determine the maximum- Returns:
- an Optional describing the maximum element, or empty if this stream is empty
-
min
Returns the minimum element of this stream according to natural order.- Returns:
- an Optional describing the minimum element, or empty if this stream is empty
-
min
Returns the minimum element of this stream according to the provided comparator.- Parameters:
le- the comparator to determine the minimum- Returns:
- an Optional describing the minimum element, or empty if this stream is empty
-
average
Calculates the average of all numeric elements in the stream.- Returns:
- an Optional containing the average, or empty if the stream is empty
-
sum
Returns the sum of all numeric elements in the stream.- Returns:
- the sum of all elements
-
count
-
anyMatch
Checks if any element in the stream matches the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if any element matches, or empty if the stream is empty
-
allMatch
Checks if all elements in the stream match the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if all elements match, or empty if the stream is empty
-
noneMatch
Checks if no elements of this stream match the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if no elements match, or empty if the stream is empty
-
findFirst
Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.- Returns:
- an Optional describing the first element of this stream
-