Function example

Description

Function represents a function that accepts one argument and produces a result.

Example

The following example shows how to use Function.


import java.util.function.Function;
/*from  w  w w . j  av  a  2 s  .c  o  m*/
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.