Java Lambda - IntUnaryOperator applyAsInt example








IntUnaryOperator applyAsInt applies this operator to the given operand.

Syntax

applyAsInt has the following syntax.

int applyAsInt(int operand)

Example

The following example shows how to use applyAsInt.

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.