TreeSet toString() method in Java with Example
The toString() method of Java TreeSet is used to return a string representation of the elements of the Collection.
The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets.This method is used mainly to display collections other than String type(for instance: Object, Integer)in a String Representation.
public String toString()
Parameter The method does not take any parameters.
Return This method returns a String representation of the collection.
Below examples illustrate the toString() method:
[For, Geeks, To, Welcome]
[10, 20, 30, 40]