The toArray() is utilized to return an array consisting of all the elements of the TreeSet.
Method Definition: def toArray: Array[A]
Return Type: It returns an array consisting of all the elements of the TreeSet.
TreeSet(1, 2, 3, 4, 5) Elements in the array: 1 2 3 4 5
TreeSet(a, e, i, o, u) Elements in the array: a e i o u
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.