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 satisfy the condition. Once the condition is no longer fulfilled, it will take all the remaining elements to return.

Example:

In the above example, the dropWhile() method will ignore all elements smaller than 5 and when an element larger than 5, it will return all the remaining elements including this element.

Result:

Method dropWhile() of Stream object in Java


Add Comment