The toList() method is utilized to display the elements of the SortedMap in the list.
Method Definition: def toList: List[A]
Return Type: It returns all the elements of the SortedMap in the list.
Example #1:
import scala.collection.immutable.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 2 - > "cs" )
val result = m 1 .toList
println(result)
}
}
|
Output:
List((2, cs), (3, geeks), (4, for))
Example #2:
import scala.collection.immutable.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( 3 - > "geeks" , 4 - > "for" , 4 - > "for" )
val result = m 1 .toList
println(result)
}
}
|
Output:
List((3, geeks), (4, for))