DoubleConsumer vs Consumer

Overview One of the biggest questions I have when studying the functional interfaces in java.util.function is why the creators made DoubleConsumer (LongConsumer, IntConsumer) while there is already a Consumer interface that can handle any kind of object. It turned out, they have solid reason to do so. Boxing, unboxing, autoboxing primer As you may already … Read more

Java Predicate & BiPredicate Tutorial

Overview The predicate interfaces in the java.util.function package return a boolean given one or some arguments. The primary purpose of the Predicate interface is to simplify the task of evaluating conditions or tests within your Java applications. It abstracts the process of writing conditional statements and allows you to represent complex conditions as reusable, composable … Read more

Java BiFunction Tutorial

Overview In Java, A BiFunction represents a function that accepts two arguments and returns a result. The interface has one abstract method apply and one default method andThen. The apply method is defined as follows: That means it accepts two arguments (t of type T and u of type U) and returns an object of … Read more

Java BiConsumer Functional Interface Tutorial

Overview The BiConsumer is a part of the java.util.function package. As the name suggest, this interface is a Consumer. That means it takes input arguments and returns void. Practical use cases This interface can be useful in various cases, for example, it can be used to create side effects like modifying state, printing, or logging. … Read more

Java Fork/Join Framework File Downloading Examples

Overview of the Fork/Join Framework in Java The Fork/Join framework in Java is an example of the divide and conquer strategy. It is best used for scenarios where you have multiple tasks that can be executed individually. There are two important classes: RecursiveTask<T> and RecursiveAction. While RecursiveTask returns a value, RecursiveAction doesn’t (Similar to Callable … Read more