UnaryOperator identity example

Description

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

Syntax

identity has the following syntax.


static <T> UnaryOperator<T> identity()

Example

The following example shows how to use identity.


import java.util.function.UnaryOperator;
/*from   w w  w  .  j  a v  a 2s.co  m*/
public class Main {

  public static void main(String[] args) {
    UnaryOperator<String> i  = (x)-> x.toUpperCase();
    
    System.out.println(i.apply("java2s.com"));
  }
}

The code above generates the following result.