Java.Java8.What are the functional interfaces of the form _To_Function?

Java has a set of primitive-specialized functional interfaces of the form:

✅ XToYFunction

These are used to convert from one primitive (or boxed) type to another efficiently — avoiding boxing and unboxing.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces of the form _To_Function?

Java.Java8.What is the functional interface BiPredicate?

Let’s dive into BiPredicate<T, U>, a functional interface used to evaluate a boolean condition based on two inputs.

✅ BiPredicate<T, U>

@FunctionalInterface
public interface BiPredicate<T, U> {
    boolean test(T t, U u);
}
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is the functional interface BiPredicate?

Java.Java8.What is the functional interface BiFunction?

Excellent question! Let’s break down the BiFunction<T, U, R> functional interface — one of the most versatile tools in Java functional programming.


✅ BiFunction<T, U, R>

@FunctionalInterface
public interface BiFunction<T, U, R> {
    R apply(T t, U u);
}
  • Takes two inputs: T and U
  • Produces a result of type R
  • It’s the two-argument version of Function<T, R>
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is the functional interface BiFunction?

Java.Java8.What is the functional interface BiConsumer?

Let’s talk about BiConsumer<T, U> — it’s part of the java.util.function package and is a functional interface used when you want to perform an action with two inputs and return nothing.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What is the functional interface BiConsumer?

Java.Java8.What are the functional interfaces Supplier, BooleanSupplier, DoubleSupplier, IntSupplier, and LongSupplier?

✅ 1. Supplier<T>

Package: java.util.function

  • Represents a function that supplies a result of type T, with no input.
@FunctionalInterface
public interface Supplier<T> {
    T get();
}

🧠 Example:

Supplier<String> greetingSupplier = () -> "Hello, world!";
System.out.println(greetingSupplier.get()); // Output: Hello, world!
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces Supplier, BooleanSupplier, DoubleSupplier, IntSupplier, and LongSupplier?

Java.Java8.What are the functional interfaces Consumer, DoubleConsumer, IntConsumer, and LongConsumer?

These are used when you accept a value and do something with it, but you don’t return a result.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces Consumer, DoubleConsumer, IntConsumer, and LongConsumer?

Java.Java8.What are the functional interfaces Predicate, DoublePredicate, IntPredicate, and LongPredicate?

✅ 1. Predicate<T>

Package: java.util.function

  • A functional interface that takes one argument of type T and returns a boolean.
@FunctionalInterface
public interface Predicate<T> {
    boolean test(T t);
}

🧠 Example:

Predicate<String> isLongWord = str -> str.length() > 5;
System.out.println(isLongWord.test("hello"));     // false
System.out.println(isLongWord.test("predicate")); // true
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces Predicate, DoublePredicate, IntPredicate, and LongPredicate?

Java.Java8.What are the functional interfaces BinaryOperator, DoubleBinaryOperator, IntBinaryOperator, and LongBinaryOperator?

A generic interface that operates on two operands of the same type and returns a result of the same type.

@FunctionalInterface
public interface BinaryOperator<T> extends BiFunction<T, T, T> {
    // No additional methods
}

🧠 Example:

BinaryOperator<Integer> add = (a, b) -> a + b;
System.out.println(add.apply(5, 7)); // Output: 12
Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces BinaryOperator, DoubleBinaryOperator, IntBinaryOperator, and LongBinaryOperator?

Java.Java8.DoubleUnaryOperator, IntUnaryOperator, and LongUnaryOperator?

✅ What do they have in common?

They are all specialized versions of UnaryOperator<T> for Java primitives: double, int, and long.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.DoubleUnaryOperator, IntUnaryOperator, and LongUnaryOperator?

Java.Java8.What are the functional interfaces UnaryOperator,

Let’s dive into UnaryOperator<T>, which is a specialized version of Function<T, R> when input and output types are the same.

Continue reading →
Posted in Без рубрики | Comments Off on Java.Java8.What are the functional interfaces UnaryOperator,