Function apply example

Description

Function apply applies this function to the given argument.

Syntax

apply has the following syntax.


R apply(T t)

Example

The following example shows how to use apply.


import java.util.function.Function;
//from  ww  w .  j av a  2  s .c  om
public class Main {

  public static void main(String[] args) {
    Function<Integer,String> converter = (i)-> Integer.toString(i);
    
   
    System.out.println(converter.apply(3).length());
    System.out.println(converter.apply(30).length());
  }
}

The code above generates the following result.