The
toArray() method of
Java SortedSet is used to form an array of the same elements as that of the SortedSet. Basically, it copies all the element from a SortedSet to a new array.
Syntax:
Object[] toArray()
Parameters: The method does not take any parameters.
Return Value: The method returns an
array containing the elements similar to the SortedSet.
Note: The toArray() method in
SortedSet is inherited from the
Set interface in Java.
Below programs illustrate the SortedSet.toArray() method:
Program 1:
Output:
The SortedSet: [For, Geeks, To, Welcome]
The array is:
For
Geeks
To
Welcome
Program 2: