Java Spliterator forEachRemaining() Method

The forEachRemaining() method of Java Interface Spliterator is used to performs the given action for each remaining element sequentially in the current thread until all elements have been processed or the action throws an exception.

Syntax

Following is the declaration of forEachRemaining() method-

Parameter

ParameterDescriptionRequired/Optional
actionIt is the action performs to check remaining elements.Required

Return

The forEachRemaining() method does not return anything. It only performs the given action for each remaining element.

Exceptions

NullPointerException- This method has thrown an exception if the specified action is null.

Compatibility Version

Java 1.8 and above

Example 1

Output:

Skype
Next Element Present? true
Remaining Name Present in the List:
Facebook
Instagram
Twitter

Example 2

Output:

Elements Exist in arraylist :
100
-200
300
-400
500

Example 3

Output:

Elements os Array-
1
2
3
4