Open In App

Scala SortedSet toMap() method with example

Last Updated : 02 Nov, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The toMap() method is utilized to return a map consisting of all the elements of the SortedSet.
Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the SortedSet.
Example #1: Scala
// Scala program of toMap() 
// method 
import scala.collection.immutable.SortedSet 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet((1, 2), (3, 4), (5, 6)) 
        
        // Applying toMap method 
        val result = s1.toMap
        
        // Display output
        println(result)
            
    } 
} 
Output:
Map(1 -> 2, 3 -> 4, 5 -> 6)
Example #2: Scala
// Scala program of toMap() 
// method 
import scala.collection.immutable.SortedSet 

// Creating object 
object GfG 
{ 

    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a SortedSet 
        val s1 = SortedSet((12, 2), (13, 4), (15, 6)) 
        
        // Applying toMap method 
        val result = s1.toMap
        
        // Display output
        println(result)
            
    } 
} 
Output:
Map(12 -> 2, 13 -> 4, 15 -> 6)

Next Article
Article Tags :

Similar Reads