Function Interface

The java.util.function.Function Interface is a Functional Interface which has

@FunctionalInterface
public interface Function<T, R> {

    /**
     * Applies this function to the given argument.
     *
     * @param t the function argument
     * @return the function result
     */
    R apply(T t);

apply as abstract method, It takes T object as the Input argument and returns an object of type R .

Usage: we can use it to map one object of one type to other object of another type.For Example below we have created one List of type String and passed it to a method expecting Function Interface with String object as input type and returned object of Integer type, so here we passed List of String which gets converted to List of Integers based upon the apply method implementation we provide

and here is the list of integers we got in output

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *