Lambda: IntPredicate avoids boxing for a primitive int test

IntPredicate takes a primitive int directly, so testing many integers avoids the autoboxing overhead a Predicate<Integer> would incur on every call.

Code
IntPredicate isEven = n -> n % 2 == 0;
System.out.println("isEven(4): " + isEven.test(4));
System.out.println("isEven(7): " + isEven.test(7));
Output
isEven(4): true
isEven(7): false
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