IntUnaryOperator compose example

Description

IntUnaryOperator compose returns a composed operator that first applies the before operator to its input, and then applies this operator to the result.

Syntax

compose has the following syntax.


default IntUnaryOperator compose(IntUnaryOperator before)

Example

The following example shows how to use compose.


import java.util.function.IntUnaryOperator;
//from   w w w  .  j a  va2 s  .  co  m
public class Main {

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

The code above generates the following result.