Java Lambda - UnaryOperator example

UnaryOperator represents an operation on a single operand that produces a result of the same type as its operand. This is a specialization of Function for the case where the operand and result are of the same type.


  1. UnaryOperator identity


The following example shows how to use UnaryOperator.

import java.util.function.UnaryOperator;
//from   w  w  w.j a  va  2  s.c o m
public class Main {

  public static void main(String[] args) {
    UnaryOperator<String> i  = (x)-> x.toUpperCase();

The code above generates the following result.