Java Stream How to - Create Function Lambda








Question

We would like to know how to create Function Lambda.

Answer

import java.util.function.Function;
/*ww w.j av  a2  s  .  c  o  m*/
public class FunctionExample {

  public static void main(String[] args) {
    Function<Integer, Integer> incrementer = (n) -> n + 1;
    System.out.println(incrementer.apply(2));
  }

}

The code above generates the following result.