Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# java.util.function

*Functional interfaces* provide target types for lambda expressions and method references. Each functional interface has a single abstract method, called the *functional method* for that functional interface, to which the lambda expression's parameter and return types are matched or adapted. Functional interfaces can provide a target type in multiple contexts, such as assignment context, method invocation, or cast context:

    // Assignment context
        Predicate<String> p = String::isEmpty;

        // Method invocation context
        stream.filter(e -> e.getSize() > 10)...

        // Cast context
        stream.map((ToIntFunction) e -> e.getSize())...

The interfaces in this package are general purpose functional interfaces used by the JDK, and are available to be used by user code as well. While they do not identify a complete set of function shapes to which lambda expressions might be adapted, they provide enough to cover common requirements. Other functional interfaces provided for specific purposes, such as `https://developer.android.com/reference/java/io/FileFilter`, are defined in the packages where they are used.

The interfaces in this package are annotated with `https://developer.android.com/reference/java/lang/FunctionalInterface`. This annotation is not a requirement for the compiler to recognize an interface as a functional interface, but merely an aid to capture design intent and enlist the help of the compiler in identifying accidental violations of design intent.

Functional interfaces often represent abstract concepts like functions, actions, or predicates. In documenting functional interfaces, or referring to variables typed as functional interfaces, it is common to refer directly to those abstract concepts, for example using "this function" instead of "the function represented by this object". When an API method is said to accept or return a functional interface in this manner, such as "applies the provided function to...", this is understood to mean a *non-null* reference to an object implementing the appropriate functional interface, unless potential nullity is explicitly specified.

The functional interfaces in this package follow an extensible naming convention, as follows:

- There are several basic function shapes, including `https://developer.android.com/reference/java/util/function/Function` (unary function from `T` to `R`), `https://developer.android.com/reference/java/util/function/Consumer` (unary function from `T` to `void`), `https://developer.android.com/reference/java/util/function/Predicate` (unary function from `T` to `boolean`), and `https://developer.android.com/reference/java/util/function/Supplier` (nullary function to `R`).
- Function shapes have a natural arity based on how they are most commonly used. The basic shapes can be modified by an arity prefix to indicate a different arity, such as `https://developer.android.com/reference/java/util/function/BiFunction` (binary function from `T` and `U` to `R`).
- There are additional derived function shapes which extend the basic function shapes, including `https://developer.android.com/reference/java/util/function/UnaryOperator` (extends `Function`) and `https://developer.android.com/reference/java/util/function/BinaryOperator` (extends `BiFunction`).
- Type parameters of functional interfaces can be specialized to primitives with additional type prefixes. To specialize the return type for a type that has both generic return type and generic arguments, we prefix `ToXxx`, as in `https://developer.android.com/reference/java/util/function/ToIntFunction`. Otherwise, type arguments are specialized left-to-right, as in `https://developer.android.com/reference/java/util/function/DoubleConsumer` or `https://developer.android.com/reference/java/util/function/ObjIntConsumer`. (The type prefix `Obj` is used to indicate that we don't want to specialize this parameter, but want to move on to the next parameter, as in `https://developer.android.com/reference/java/util/function/ObjIntConsumer`.) These schemes can be combined, as in `IntToDoubleFunction`.
- If there are specialization prefixes for all arguments, the arity prefix may be left out (as in `https://developer.android.com/reference/java/util/function/ObjIntConsumer`).

## Interfaces

|---|---|
| [BiConsumer](https://developer.android.com/reference/java/util/function/BiConsumer)\<T, U\> | Represents an operation that accepts two input arguments and returns no result. |
| [BiFunction](https://developer.android.com/reference/java/util/function/BiFunction)\<T, U, R\> | Represents a function that accepts two arguments and produces a result. |
| [BinaryOperator](https://developer.android.com/reference/java/util/function/BinaryOperator)\<T\> | Represents an operation upon two operands of the same type, producing a result of the same type as the operands. |
| [BiPredicate](https://developer.android.com/reference/java/util/function/BiPredicate)\<T, U\> | Represents a predicate (boolean-valued function) of two arguments. |
| [BooleanSupplier](https://developer.android.com/reference/java/util/function/BooleanSupplier) | Represents a supplier of `boolean`-valued results. |
| [Consumer](https://developer.android.com/reference/java/util/function/Consumer)\<T\> | Represents an operation that accepts a single input argument and returns no result. |
| [DoubleBinaryOperator](https://developer.android.com/reference/java/util/function/DoubleBinaryOperator) | Represents an operation upon two `double`-valued operands and producing a `double`-valued result. |
| [DoubleConsumer](https://developer.android.com/reference/java/util/function/DoubleConsumer) | Represents an operation that accepts a single `double`-valued argument and returns no result. |
| [DoubleFunction](https://developer.android.com/reference/java/util/function/DoubleFunction)\<R\> | Represents a function that accepts a double-valued argument and produces a result. |
| [DoublePredicate](https://developer.android.com/reference/java/util/function/DoublePredicate) | Represents a predicate (boolean-valued function) of one `double`-valued argument. |
| [DoubleSupplier](https://developer.android.com/reference/java/util/function/DoubleSupplier) | Represents a supplier of `double`-valued results. |
| [DoubleToIntFunction](https://developer.android.com/reference/java/util/function/DoubleToIntFunction) | Represents a function that accepts a double-valued argument and produces an int-valued result. |
| [DoubleToLongFunction](https://developer.android.com/reference/java/util/function/DoubleToLongFunction) | Represents a function that accepts a double-valued argument and produces a long-valued result. |
| [DoubleUnaryOperator](https://developer.android.com/reference/java/util/function/DoubleUnaryOperator) | Represents an operation on a single `double`-valued operand that produces a `double`-valued result. |
| [Function](https://developer.android.com/reference/java/util/function/Function)\<T, R\> | Represents a function that accepts one argument and produces a result. |
| [IntBinaryOperator](https://developer.android.com/reference/java/util/function/IntBinaryOperator) | Represents an operation upon two `int`-valued operands and producing an `int`-valued result. |
| [IntConsumer](https://developer.android.com/reference/java/util/function/IntConsumer) | Represents an operation that accepts a single `int`-valued argument and returns no result. |
| [IntFunction](https://developer.android.com/reference/java/util/function/IntFunction)\<R\> | Represents a function that accepts an int-valued argument and produces a result. |
| [IntPredicate](https://developer.android.com/reference/java/util/function/IntPredicate) | Represents a predicate (boolean-valued function) of one `int`-valued argument. |
| [IntSupplier](https://developer.android.com/reference/java/util/function/IntSupplier) | Represents a supplier of `int`-valued results. |
| [IntToDoubleFunction](https://developer.android.com/reference/java/util/function/IntToDoubleFunction) | Represents a function that accepts an int-valued argument and produces a double-valued result. |
| [IntToLongFunction](https://developer.android.com/reference/java/util/function/IntToLongFunction) | Represents a function that accepts an int-valued argument and produces a long-valued result. |
| [IntUnaryOperator](https://developer.android.com/reference/java/util/function/IntUnaryOperator) | Represents an operation on a single `int`-valued operand that produces an `int`-valued result. |
| [LongBinaryOperator](https://developer.android.com/reference/java/util/function/LongBinaryOperator) | Represents an operation upon two `long`-valued operands and producing a `long`-valued result. |
| [LongConsumer](https://developer.android.com/reference/java/util/function/LongConsumer) | Represents an operation that accepts a single `long`-valued argument and returns no result. |
| [LongFunction](https://developer.android.com/reference/java/util/function/LongFunction)\<R\> | Represents a function that accepts a long-valued argument and produces a result. |
| [LongPredicate](https://developer.android.com/reference/java/util/function/LongPredicate) | Represents a predicate (boolean-valued function) of one `long`-valued argument. |
| [LongSupplier](https://developer.android.com/reference/java/util/function/LongSupplier) | Represents a supplier of `long`-valued results. |
| [LongToDoubleFunction](https://developer.android.com/reference/java/util/function/LongToDoubleFunction) | Represents a function that accepts a long-valued argument and produces a double-valued result. |
| [LongToIntFunction](https://developer.android.com/reference/java/util/function/LongToIntFunction) | Represents a function that accepts a long-valued argument and produces an int-valued result. |
| [LongUnaryOperator](https://developer.android.com/reference/java/util/function/LongUnaryOperator) | Represents an operation on a single `long`-valued operand that produces a `long`-valued result. |
| [ObjDoubleConsumer](https://developer.android.com/reference/java/util/function/ObjDoubleConsumer)\<T\> | Represents an operation that accepts an object-valued and a `double`-valued argument, and returns no result. |
| [ObjIntConsumer](https://developer.android.com/reference/java/util/function/ObjIntConsumer)\<T\> | Represents an operation that accepts an object-valued and a `int`-valued argument, and returns no result. |
| [ObjLongConsumer](https://developer.android.com/reference/java/util/function/ObjLongConsumer)\<T\> | Represents an operation that accepts an object-valued and a `long`-valued argument, and returns no result. |
| [Predicate](https://developer.android.com/reference/java/util/function/Predicate)\<T\> | Represents a predicate (boolean-valued function) of one argument. |
| [Supplier](https://developer.android.com/reference/java/util/function/Supplier)\<T\> | Represents a supplier of results. |
| [ToDoubleBiFunction](https://developer.android.com/reference/java/util/function/ToDoubleBiFunction)\<T, U\> | Represents a function that accepts two arguments and produces a double-valued result. |
| [ToDoubleFunction](https://developer.android.com/reference/java/util/function/ToDoubleFunction)\<T\> | Represents a function that produces a double-valued result. |
| [ToIntBiFunction](https://developer.android.com/reference/java/util/function/ToIntBiFunction)\<T, U\> | Represents a function that accepts two arguments and produces an int-valued result. |
| [ToIntFunction](https://developer.android.com/reference/java/util/function/ToIntFunction)\<T\> | Represents a function that produces an int-valued result. |
| [ToLongBiFunction](https://developer.android.com/reference/java/util/function/ToLongBiFunction)\<T, U\> | Represents a function that accepts two arguments and produces a long-valued result. |
| [ToLongFunction](https://developer.android.com/reference/java/util/function/ToLongFunction)\<T\> | Represents a function that produces a long-valued result. |
| [UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)\<T\> | Represents an operation on a single operand that produces a result of the same type as its operand. |

-

  ## Interfaces

  - [BiConsumer](https://developer.android.com/reference/java/util/function/BiConsumer)
  - [BiFunction](https://developer.android.com/reference/java/util/function/BiFunction)
  - [BinaryOperator](https://developer.android.com/reference/java/util/function/BinaryOperator)
  - [BiPredicate](https://developer.android.com/reference/java/util/function/BiPredicate)
  - [BooleanSupplier](https://developer.android.com/reference/java/util/function/BooleanSupplier)
  - [Consumer](https://developer.android.com/reference/java/util/function/Consumer)
  - [DoubleBinaryOperator](https://developer.android.com/reference/java/util/function/DoubleBinaryOperator)
  - [DoubleConsumer](https://developer.android.com/reference/java/util/function/DoubleConsumer)
  - [DoubleFunction](https://developer.android.com/reference/java/util/function/DoubleFunction)
  - [DoublePredicate](https://developer.android.com/reference/java/util/function/DoublePredicate)
  - [DoubleSupplier](https://developer.android.com/reference/java/util/function/DoubleSupplier)
  - [DoubleToIntFunction](https://developer.android.com/reference/java/util/function/DoubleToIntFunction)
  - [DoubleToLongFunction](https://developer.android.com/reference/java/util/function/DoubleToLongFunction)
  - [DoubleUnaryOperator](https://developer.android.com/reference/java/util/function/DoubleUnaryOperator)
  - [Function](https://developer.android.com/reference/java/util/function/Function)
  - [IntBinaryOperator](https://developer.android.com/reference/java/util/function/IntBinaryOperator)
  - [IntConsumer](https://developer.android.com/reference/java/util/function/IntConsumer)
  - [IntFunction](https://developer.android.com/reference/java/util/function/IntFunction)
  - [IntPredicate](https://developer.android.com/reference/java/util/function/IntPredicate)
  - [IntSupplier](https://developer.android.com/reference/java/util/function/IntSupplier)
  - [IntToDoubleFunction](https://developer.android.com/reference/java/util/function/IntToDoubleFunction)
  - [IntToLongFunction](https://developer.android.com/reference/java/util/function/IntToLongFunction)
  - [IntUnaryOperator](https://developer.android.com/reference/java/util/function/IntUnaryOperator)
  - [LongBinaryOperator](https://developer.android.com/reference/java/util/function/LongBinaryOperator)
  - [LongConsumer](https://developer.android.com/reference/java/util/function/LongConsumer)
  - [LongFunction](https://developer.android.com/reference/java/util/function/LongFunction)
  - [LongPredicate](https://developer.android.com/reference/java/util/function/LongPredicate)
  - [LongSupplier](https://developer.android.com/reference/java/util/function/LongSupplier)
  - [LongToDoubleFunction](https://developer.android.com/reference/java/util/function/LongToDoubleFunction)
  - [LongToIntFunction](https://developer.android.com/reference/java/util/function/LongToIntFunction)
  - [LongUnaryOperator](https://developer.android.com/reference/java/util/function/LongUnaryOperator)
  - [ObjDoubleConsumer](https://developer.android.com/reference/java/util/function/ObjDoubleConsumer)
  - [ObjIntConsumer](https://developer.android.com/reference/java/util/function/ObjIntConsumer)
  - [ObjLongConsumer](https://developer.android.com/reference/java/util/function/ObjLongConsumer)
  - [Predicate](https://developer.android.com/reference/java/util/function/Predicate)
  - [Supplier](https://developer.android.com/reference/java/util/function/Supplier)
  - [ToDoubleBiFunction](https://developer.android.com/reference/java/util/function/ToDoubleBiFunction)
  - [ToDoubleFunction](https://developer.android.com/reference/java/util/function/ToDoubleFunction)
  - [ToIntBiFunction](https://developer.android.com/reference/java/util/function/ToIntBiFunction)
  - [ToIntFunction](https://developer.android.com/reference/java/util/function/ToIntFunction)
  - [ToLongBiFunction](https://developer.android.com/reference/java/util/function/ToLongBiFunction)
  - [ToLongFunction](https://developer.android.com/reference/java/util/function/ToLongFunction)
  - [UnaryOperator](https://developer.android.com/reference/java/util/function/UnaryOperator)