Scala Mutable SortedSet toString() method
In Scala mutable collections, SortedSet toString() method is utilized to return a string consisting of all the elements of the SortedSet.
Method Definition: def toString(): String
Return Type: It returns a string consisting of all the elements of the SortedSet.
Example #1:
// Scala program of toString() // method import scala.collection.mutable.SortedSet // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a SortedSet val s 1 = SortedSet( 1 , 3 , 44 , 5 ) // Applying toString method val result = s 1 .toString // Display output println(result) } } |
Output:
TreeSet(1, 3, 5, 44)
Example #2:
// Scala program of toString() // method import scala.collection.mutable.SortedSet // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a SortedSet val s 1 = SortedSet( 444 , 555 , 777 , 666 , 111 ) // Applying toString method val result = s 1 .toString // Display output println(result) } } |
Output:
TreeSet(111, 444, 555, 666, 777)