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

# Class Optional

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

public class Optional extends Object
Represents an optional value that may or may not be present.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `get()`
  Returns the contained value, or throws an exception if empty.
  `void`
  `ifPresent(LambdaExpression le)`
  If a value is present, invokes the given lambda with the value.
  `Object`
  `orElse(Object other)`
  Returns the contained value, or the given default value if empty.
  `Object`
  `orElseGet(Object le)`
  Returns the contained value, or the result of evaluating the given lambda if empty.

  ### Methods inherited from class Object

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

- ## Method Details

  - ### get

    public Object get() throws ELException
    Returns the contained value, or throws an exception if empty.
    Returns:
      The contained value
    Throws:
      `ELException` - if the value is not present

  - ### ifPresent

    public void ifPresent(LambdaExpression le)
    If a value is present, invokes the given lambda with the value.
    Parameters:
      `le` - The lambda expression to invoke

  - ### orElse

    public Object orElse(Object other)
    Returns the contained value, or the given default value if empty.
    Parameters:
      `other` - The default value
    Returns:
      The contained value or the default

  - ### orElseGet

    public Object orElseGet(Object le)
    Returns the contained value, or the result of evaluating the given lambda if empty.
    Parameters:
      `le` - The lambda expression or already-evaluated value
    Returns:
      The contained value or the result of the lambda