AbstractSet toArray() method in Java with Example
The toArray() method of Java AbstractSet is used to form an array of the same elements as that of the AbstractSet. Basically, it copies all the element from a AbstractSet to a new array.
Object arr = AbstractSet.toArray()
Parameters: The method does not take any parameters.
Return Value: The method returns an array containing the elements similar to the AbstractSet.
Below programs illustrate the AbstractSet.toArray() method:
The AbstractSet: [For, Geeks, To, Welcome] The array is: For Geeks To Welcome
The AbstractSet: [5, 10, 15, 20, 25, 30] The array is: 5 10 15 20 25 30
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.