Javatpoint Logo
Javatpoint Logo

Java Spliterator tryAdvance() Method

The tryAdvance() is a method of Java Interface Spliterator which is used to get the existing elements upon performing the specified action on it.

Syntax

Following is the declaration of tryAdvance() method-

Parameter

Parameter Description Required/Optional
action It is the action for checking elements. Required

Return

The tryAdvance() method returns true if there is a next element present upon entry to this method, otherwise returns false.

Exceptions

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

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

Jasmine
Element exists: true
 --- bulk traversal
Rose
Lotus
 --Attempting tryAdvance again--
Element exists: false

Example 2

Test it Now

Output:

Name: Rahul
Name: Abhi
Name: Suresh
Name: Rani
Name: Nikki
Name: Rosy
Name: Prem

Example 3

Test it Now

Output:

Elements of arraylist: 
1
2
3
4
5



Help Others, Please Share

facebook twitter pinterest