Javatpoint Logo
Javatpoint Logo

Java Function Interface

It is a functional interface. It is used to refer method by specifying type of parameter. It returns a result back to the referred function.

Java Function Interface Methods

Method Description
default <V> Function<T,V> andThen(Function<? super R,? extends V> after) It returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
static <T> Function<T,T> identity() It returns a function that always returns its input argument.
R apply(T t) It applies this function to the given argument.
default <V> Function<V,R> compose(Function<? super V,? extends T> before) It Returns a composed function that first applies the before function to its input, and then applies this function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Java Function Interface Example 1

Output:

Hello Peter

Java Function Interface Example 2

Output:

Sum of list values: 100





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA