IntUnaryOperator takes and returns a primitive int, making it the boxing-free counterpart of UnaryOperator<Integer> for simple numeric transforms.
IntUnaryOperator square = n -> n * n;
System.out.println("square.applyAsInt(6) = " + square.applyAsInt(6));
System.out.println("square.applyAsInt(-3) = " + square.applyAsInt(-3));
square.applyAsInt(6) = 36
square.applyAsInt(-3) = 9
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