Scala Mutable SortedSet toMap() method
In Scala mutable collections, 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:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet(( 1 , 2 ), ( 3 , 4 ), ( 5 , 6 ))
val result = s 1 .toMap
println(result)
}
}
|
Output:
Map(1 -> 2, 3 -> 4, 5 -> 6)
Example #2:
import scala.collection.mutable.SortedSet
object GfG
{
def main(args : Array[String])
{
val s 1 = SortedSet(( 12 , 2 ), ( 13 , 4 ), ( 15 , 6 ))
val result = s 1 .toMap
println(result)
}
}
|
Output:
Map(12 -> 2, 13 -> 4, 15 -> 6)
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...