UnaryOperator example

Description

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.

Example

The following example shows how to use UnaryOperator.


import java.util.function.UnaryOperator;
/* w  w  w .  j  a  va2 s  . c om*/
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.