Java Lambda - IntFunction example








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

Method

  1. IntFunction apply

Example

The following example shows how to use IntFunction.

import java.util.function.IntFunction;
// ww w .jav  a 2 s  . c  o m
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.