Lambda: UnaryOperator is a Function whose input and output types match

UnaryOperator<T> is a specialization of Function<T, T> for the common case of transforming a value into another value of the same type, such as a String into a String.

Code
UnaryOperator<String> shout = s -> s.toUpperCase() + "!";
System.out.println(shout.apply("hello"));
Output
HELLO!
Advertisement
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-09-27

© Java Coding Hub · About · Contact · Privacy · Terms