Java Lambda - DoubleUnaryOperator identity example








DoubleUnaryOperator identity returns a unary operator that always returns its input argument.

Syntax

identity has the following syntax.

static DoubleUnaryOperator identity()

Example

The following example shows how to use identity.

import java.util.function.DoubleUnaryOperator;
//from w  ww .  ja va 2 s .  c  om
public class Main {

  public static void main(String[] args) {
    DoubleUnaryOperator id = DoubleUnaryOperator.identity();
    
   
    System.out.println(id.applyAsDouble(3.14));
  }
}

The code above generates the following result.