Method iterate() of Stream object in Java

In Java 8, the iterate() method has been introduced and it has only two parameters and will help us to create an infinite stream. Content:

Example:

When running the above example, you will see that a Stream object contains endless numbers beginning at… Read More

Method ofNullable() of Stream object in Java

This method was added from Java 9.

This method will return the Stream object of an element in case this element is not null; if it is null, it returns an empty Stream. Example:

When you run the above code, it will print… Read More

Method dropWhile() of Stream object in Java

This method was added from Java 9.

This method also has the parameter Predicate interface and its function is the opposite of the takeWhile() method. This method also passes each element in your Stream object from left to right and ignores all elements that… Read More

Method takeWhile() of Stream object in Java

This method was added from Java 9.

The parameter of this method is the Predicate interface and this method takes the elements in your Stream object from left to right, until the condition of the Predicate object is no longer fulfilled. Example:

In… Read More

Using flatMap() method of Stream object in Java

When working with Stream in Java, sometime we can have a Stream with datatype of a List, Set or Array of object. For example:

Here, we have List of List of String object and when convert into Stream object, we have Stream of List… Read More

Sort a Map using Stream and Collectors in Java

In this tutorial, I will show you how to order elements in a Map object using the Stream object and the Collectors object in Java by key and by value. For example, we have a Map object like this:

Prior to Java 8, to… Read More