Predicate and Function functional interfaces in Java 8 or later

In this example you will see what are Predicate and Function functional interfaces in Java 8 or later version of Java. Functional interfaces provide target types for lambda expressions and method references. Each functional interface has a single abstract method, called functional method for that functional interface, to which the lambda expression’s parameter and return types are matched. The Predicate…

Difference Between Parallel Stream And CompletableFuture In Java

Parallel Stream Vs CompletableFuture I am going to discuss here CompletableFuture vs Parallel Stream in Java programming language. CompletableFuture extends Future with added advantage to allow the tasks finish in an ad hoc manner, whereas, in Parallel Stream task is divided into sub-tasks and run on separate threads to be completed faster. Both CompletableFuture and Parallel Stream were added in…

Check a Given Date is Past, Today or Future’s Date in Java

Past, Present Or Future’s Date In this example I am going to show you how to check if an input date is past date or today’s date or future date. For this example you should use at least Java version 8. Java 8 or higher version provides thread safe version of date time API classes that can be used safely…

Parallelism Example in Java Stream API

I am going to show you how to work with parallel stream in Java 8 or higher version of Java. In parallel computing a task is divided into sub-tasks and these sub-tasks are computed parallelly in each separate threads and finally the result of the solution for each sub-tasks is combined. One of the features for computing parallelism is to…

Add Or Subtract Days Weeks Months Years On Java 8 Date

Java 8 Date In this tutorial I am going to show you how to add days, weeks, months, years to a particular date in Java 8 or later. Similarly I will also show how to substract days, weeks, months, years from a particular date. The date is actually LocalDate API in Java 8 or later. The one of the important…

Find Unique Strings Or Objects Using Java Stream API

Unique Strings/Objects In this tutorial you will see an example on how to find unique strings or objects using Java stream API. Stream API was introduced in Java 8 and I am going to show you how to use this stream API to remove duplicates from strings or objects. Java stream API has a method distinct() that removes duplicates and…

Supplier, Consumer and BiConsumer in Java 8

Introduction I will discuss here about the new feature added to Java 8 – a functional interface, Supplier, Consumer and BiConsumer. In simple words, a supplier is a method that returns a value. A supplier is any method which takes no arguments and returns a value. Its job is to supply an instance of an expected class. Whereas, a consumer…

Convert List of Map Objects Into List Of Objects Using Java Stream

Map To List Objects Here I will show you how to convert List of Map objects into List of objects using Java 8’s or later’s Stream API. The List of Map objects can be found as a result of selecting multiple records from database table or any other sources. Then you may need to convert into List of objects to…

Convert Milliseconds into Years, Months, Weeks, Days, Hours, Minutes, Seconds in Java

Introduction This example shows you how to convert milliseconds into years, months, weeks, days, hours, minutes, seconds in Java. Sometimes we need to convert the milliseconds into years or months or weeks or days or hours or minutes or seconds. For example, when you want to check the exact time taken by a program to execute then you may need…

Convert Milliseconds into Days, Hours, Minutes, Seconds in Java

Introduction This example shows you hot to convert milliseconds into days, hours, minutes, seconds in Java. Sometimes you need to convert the milliseconds into days or hours or minutes or seconds. Typically when you want to check the exact time taken to execute a program then you may need to calculate the time. So in this case you get the…