Java TreeSet Spliterator() Method

The spliterator() method of TreeSet class is used to split the set elements and iterate them one by one.

Syntax:

Return:

It returns the spliterator elements of the set.

Example 1

Output:

TreeSet: [4, 6, 9, 12, 18]
Elements of TreeSet after using spliterator() method: 
4
6
9
12
18

Example 2

Output:

Elements in TreeSet: 
shristee  vishwakarma  Analyst
shweta    singh        Accountant
suman     chandra      Computer Engineer 
Elements of TreeSet after using spliterator() method: 
shristee  vishwakarma  Analyst
shweta    singh        Accountant
suman     chandra      Computer Engineer