Java Lambda - IntUnaryOperator example








IntUnaryOperator represents an operation on a single int-valued operand that produces an int-valued result. This is the primitive type specialization of UnaryOperator for int.

Method

  1. IntUnaryOperator applyAsInt
  2. IntUnaryOperator compose
  3. IntUnaryOperator andThen
  4. IntUnaryOperator identity




Example

The following example shows how to use IntUnaryOperator.

import java.util.function.IntUnaryOperator;

public class Main {

  public static void main(String[] args) {
    IntUnaryOperator i = (x) -> x*x;
    System.out.println(i.applyAsInt(2));
  }
}

The code above generates the following result.