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.


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


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;

The code above generates the following result.