Java - Commonly Used Functional Interfaces

Introduction

Java has many frequently used functional interfaces in the package java.util.function.

The following table lists Functional Interfaces Declared in the Package java.util.function

Interface Name
Method
Description
Function<T,R>

R apply(T t)

a function that takes an argument of type T
and returns a result of type R.
BiFunction<T,U,R>

R apply(T t, U u)

a function that takes two arguments of types T
and U, and returns a result of type R.
Predicate<T>

boolean test(T t)

represents a condition that returns true or false
for the specified argument.
BiPredicate<T,U>
boolean test(T t, U u)
a predicate with two arguments.
Consumer<T>

void accept(T t)

an operation that takes an argument, operates
on it to produce some side effects, and returns no result.
BiConsumer<T,U>


void accept(T t, U u)


an operation that takes two arguments,
operates on them to produce some side effects, and
returns no result.
Supplier<T>
T get()
a supplier that returns a value.
UnaryOperator<T>

T apply(T t)

Inherits from Function<T,T>. Represents a function that
takes an argument and returns a result of the same type.
BinaryOperator<T>


T apply(T t1, T t2)


Inherits from BiFunction<T,T,T>. Represents a function
that takes two arguments of the same type and returns a
result of the same.

There are several specialized versions of interfaces above.

For example, IntConsumer is a specialized version of Consumer<T>.