Javatpoint Logo
Javatpoint Logo

Java Spliterator trySplit() Method

The trySplit() method of Java Interface Spliterator is used to split the invoking spliterator. If this spliterator can be partitioned, returns a reference to a new spliterator for the partition, otherwise, it returns null.

Syntax

Following is the declaration of trySplit() method-

Parameter

This method does not accept any parameter.

Return

The trySplit() method returns a spliterator covering some portion of the elements or returns null if this spliterator cannot be split.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

MySQL
Python
--Traversing the other half of the spliterator---
Java
Android

Example 2

Test it Now

Output:

Elements of ArrayList: 
101
201
301
401
501
Output from splitr2: 
101
201
Output from splitr1: 
301
401
501



Help Others, Please Share

facebook twitter pinterest