Java Lambda - DoubleUnaryOperator andThen example








DoubleUnaryOperator andThen returns a composed operator that first applies this operator to its input, and then applies the after operator to the result.

Syntax

andThen has the following syntax.

default DoubleUnaryOperator andThen(DoubleUnaryOperator after)

Example

The following example shows how to use andThen.

import java.util.function.DoubleUnaryOperator;
/*from   w  ww.  j av a 2 s . c  om*/
public class Main {

  public static void main(String[] args) {
    DoubleUnaryOperator square = (x) -> {return x*x;};
    
    DoubleUnaryOperator doubleValue = (x) -> {return 2*x;};
    
    System.out.println(doubleValue.andThen(square).applyAsDouble(3.14));
  }
}

The code above generates the following result.