IntFunction example

Description

IntFunction represents a function that accepts an int-valued argument and produces a result. This is the int-consuming primitive specialization for Function.

Example

The following example shows how to use IntFunction.


import java.util.function.IntFunction;
/*from   w w  w.  ja  va2  s. c  om*/
public class Main {

  public static void main(String[] args) {
    IntFunction<String> i = (x)->Integer.toString(x);
    
    System.out.println(i.apply(3).length());

  }
}

The code above generates the following result.