Open In App

Scala Mutable SortedSet toString() method

Last Updated : 26 Mar, 2020
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
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
// 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 s1 = SortedSet(1, 3, 44, 5) 
        
        // Applying toString method 
        val result = s1.toString
        
        // Display output
        println(result)
            
    } 
} 
Output:
TreeSet(1, 3, 5, 44)
Example #2: Scala
// 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 s1 = SortedSet(444, 555, 777, 666, 111) 
        
        // Applying toString method 
        val result = s1.toString
        
        // Display output
        println(result)
            
    } 
} 
Output:
TreeSet(111, 444, 555, 666, 777)

Similar Reads