Skip to main content

Difference between Predicate, Function, Consumer, and Supplier.

Entry Java
Quick Answer Predicate: test(T t) returns boolean - used for filtering. Function: apply(T t) returns R - transformation. Consumer: accept(T t) returns void - side effects. Supplier: get() returns T - produces values. BiFunction, BiConsumer, BiPredicate handle two arguments. UnaryOperator is Function. BinaryOperator is BiFunction. These cover most functional programming needs.

Answer

Predicate tests conditions and returns boolean.
Function transforms input to output.
Consumer performs action without returning.
Supplier provides a value without input.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice