Java Spliterator trySplit() Method

7 Jan 2025 | 2 min read

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

Output:

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

Example 2

Output:

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