Stream (Apache Tomcat 9.0.120 API Documentation)
Description: declaration: package: org.apache.el.stream, class: Stream

# Class Stream

java.lang.Object
org.apache.el.stream.Stream

public class Stream extends Object
A stream of elements supporting sequential operations such as filter, map, reduce, and various terminal operations.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Stream(Iterator<Object> iterator)`
  Constructs a new Stream from the given iterator.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Optional`
  `allMatch(LambdaExpression le)`
  Checks if all elements in the stream match the given predicate.
  `Optional`
  `anyMatch(LambdaExpression le)`
  Checks if any element in the stream matches the given predicate.
  `Optional`
  `average()`
  Calculates the average of all numeric elements in the stream.
  `Long`
  `count()`
  Counts the number of elements in the stream.
  `Stream`
  `distinct()`
  Returns a stream consisting of the distinct elements of this stream.
  `Stream`
  `filter(LambdaExpression le)`
  Returns a stream consisting of the elements that match the given predicate.
  `Optional`
  `findFirst()`
  Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.
  `Stream`
  `flatMap(LambdaExpression le)`
  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.
  `Object`
  `forEach(LambdaExpression le)`
  Performs an action for each element of this stream.
  `Iterator<?>`
  `iterator()`
  Returns the underlying iterator for this stream.
  `Stream`
  `limit(Number count)`
  Returns a stream consisting of the first `count` elements of this stream.
  `Stream`
  `map(LambdaExpression le)`
  Returns a stream consisting of the results of applying the given function to the elements of this stream.
  `Optional`
  `max()`
  Returns the maximum element of this stream according to natural order.
  `Optional`
  `max(LambdaExpression le)`
  Returns the maximum element of this stream according to the provided comparator.
  `Optional`
  `min()`
  Returns the minimum element of this stream according to natural order.
  `Optional`
  `min(LambdaExpression le)`
  Returns the minimum element of this stream according to the provided comparator.
  `Optional`
  `noneMatch(LambdaExpression le)`
  Checks if no elements of this stream match the given predicate.
  `Stream`
  `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.
  `Object`
  `reduce(Object seed, LambdaExpression le)`
  Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.
  `Optional`
  `reduce(LambdaExpression le)`
  Performs a reduction on the elements of this stream, using the provided accumulator function.
  `Stream`
  `sorted()`
  Returns a stream consisting of the elements of this stream, sorted according to natural order.
  `Stream`
  `sorted(LambdaExpression le)`
  Returns a stream consisting of the elements of this stream, sorted according to the order induced by the provided comparator.
  `Stream`
  `substream(Number start)`
  Returns a stream consisting of the elements of this stream from the specified start position to the end.
  `Stream`
  `substream(Number start, Number 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.
  `Number`
  `sum()`
  Returns the sum of all numeric elements in the stream.
  `Object[]`
  `toArray()`
  Returns an array containing all the elements of this stream.
  `List<Object>`
  `toList()`
  Returns a list containing all the elements of this stream.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Stream

    public Stream(Iterator<Object> iterator)
    Constructs a new Stream from the given iterator.
    Parameters:
      `iterator` - the iterator providing the stream elements

- ## Method Details

  - ### filter

    public Stream filter(LambdaExpression le)
    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

    public Stream map(LambdaExpression le)
    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

    public Stream flatMap(LambdaExpression le)
    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

    public Stream distinct()
    Returns a stream consisting of the distinct elements of this stream.
    Returns:
      the new stream with distinct elements

  - ### sorted

    public Stream sorted()
    Returns a stream consisting of the elements of this stream, sorted according to natural order.
    Returns:
      the new sorted stream

  - ### sorted

    public Stream sorted(LambdaExpression le)
    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

    public Object forEach(LambdaExpression le)
    Performs an action for each element of this stream.
    Parameters:
      `le` - the action to perform for each element
    Returns:
      null

  - ### peek

    public Stream 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.
    Parameters:
      `le` - the action to perform on each element
    Returns:
      the new stream

  - ### iterator

    public Iterator<?> iterator()
    Returns the underlying iterator for this stream.
    Returns:
      the underlying iterator

  - ### limit

    public Stream limit(Number count)
    Returns a stream consisting of the first `count` elements of this stream.
    Parameters:
      `count` - the number of elements to limit to
    Returns:
      the new limited stream

  - ### substream

    public Stream substream(Number start)
    Returns a stream consisting of the elements of this stream from the specified start position to the end.
    Parameters:
      `start` - the start position (inclusive)
    Returns:
      the new substream

  - ### substream

    public Stream substream(Number start, Number 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.
    Parameters:
      `start` - the start position (inclusive)
      `end` - the end position (exclusive)
    Returns:
      the new substream

  - ### toList

    public List<Object> toList()
    Returns a list containing all the elements of this stream.
    Returns:
      the list of elements

  - ### toArray

    public Object[] toArray()
    Returns an array containing all the elements of this stream.
    Returns:
      the array of elements

  - ### reduce

    public Optional reduce(LambdaExpression le)
    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

    public Object reduce(Object seed, LambdaExpression le)
    Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.
    Parameters:
      `seed` - the initial value for the reduction
      `le` - the accumulator function
    Returns:
      the result of the reduction

  - ### max

    public Optional 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

    public Optional max(LambdaExpression le)
    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

    public Optional 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

    public Optional min(LambdaExpression le)
    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

    public Optional 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

    public Number sum()
    Returns the sum of all numeric elements in the stream.
    Returns:
      the sum of all elements

  - ### count

    public Long count()
    Counts the number of elements in the stream.
    Returns:
      the number of elements

  - ### anyMatch

    public Optional anyMatch(LambdaExpression le)
    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

    public Optional allMatch(LambdaExpression le)
    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

    public Optional noneMatch(LambdaExpression le)
    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

    public Optional 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