Home

javautilfunctionConsumer

java.util.function is a Java package introduced in Java 8 that defines a set of generic functional interfaces designed to work with lambda expressions and method references. It provides standard building blocks for functional-style programming, enabling behavior to be passed as data and composed or transformed.

Core interfaces include Function<T,R>, which represents a function that takes a T and returns an R and

The package also provides primitive specializations to avoid boxing and unboxing overhead, such as ToIntFunction<T>, ToLongFunction<T>,

Common usage patterns include using Function as map in streams, Predicate for filtering, and Consumer for side-effect

exposes
the
apply
method;
Predicate<T>,
a
boolean-valued
function
of
a
T
with
a
test
method;
Consumer<T>,
which
accepts
a
T
and
returns
void
via
the
accept
method;
and
Supplier<T>,
which
supplies
a
T
via
the
get
method.
Additionally,
UnaryOperator<T>
represents
a
Function<T,T>
for
single-argument
operations,
while
BinaryOperator<T>
represents
a
BiFunction<T,T,T>
for
two-argument
operations.
and
ToDoubleFunction<T>,
along
with
corresponding
predicates
(IntPredicate,
LongPredicate,
DoublePredicate),
consumers
(IntConsumer,
LongConsumer,
DoubleConsumer),
and
operators
(IntUnaryOperator,
LongUnaryOperator,
DoubleUnaryOperator,
and
their
binary
counterparts).
There
are
also
generic
functional
interfaces
like
Function,
Predicate,
and
Consumer
with
specific
primitive
mapped
variants.
actions,
with
Supplier
used
to
produce
values.
Default
and
static
methods
in
these
interfaces
provide
composition
utilities,
such
as
Function.andThen
and
Function.compose,
and
Predicate’s
and,
or,
and
negate,
enabling
flexible
building
of
complex
behavior
from
simple
components.
Overall,
java.util.function
provides
a
standard,
type-safe
toolkit
for
expressing
behavioral
logic
in
a
functional
style.