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.
UnaryOperator<String> shout = s -> s.toUpperCase() + "!";
System.out.println(shout.apply("hello"));
HELLO!
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