Java Lambda - UnaryOperator identity example

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


identity has the following syntax.

static <T> UnaryOperator<T> identity()


The following example shows how to use identity.

import java.util.function.UnaryOperator;
/*  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();

The code above generates the following result.