Scala SortedSet toMap() method with example Last Updated : 02 Nov, 2019 Summarize Comments Improve Suggest changes Share 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) Comment More infoAdvertise with us Next Article Scala SortedSet take() method with example G gopaldave Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala SortedSet take() method with example The take() method is utilized to return a SortedSet consisting of first 'n' elements of the SortedSet. Method Definition: def take(n: Int): SortedSet[A] Where 'n' is specifies the number of element to select. Return Type: It returns a SortedSet consisting of first 'n' elements of the SortedSet. Exam 1 min read Scala SortedSet toSeq() method with example The toSeq() method is utilized to return a seq consisting of all the elements of the SortedSet. Method Definition: def toSeq: Seq[A] Return Type: It returns a seq consisting of all the elements of the SortedSet. Example #1: Scala // Scala program of toSeq() // method import scala.collection.immutabl 1 min read Scala SortedSet toArray() method with example The toArray() is utilized to return an array consisting of all the elements of the SortedSet. Method Definition: def toArray: Array[A] Return Type: It returns an array consisting of all the elements of the SortedSet. Example #1: Scala // Scala program of toArray() // method import scala.collection.i 1 min read Scala Set toMap() method with example The toMap() method is utilized to return a map consisting of all the elements of the set. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the set. Example #1: Scala // Scala program of toMap() // method // Creating object object GfG { // 1 min read Scala SortedSet toList() method with example The toList() method is utilized to return a list consisting of all the elements of the SortedSet. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the SortedSet. Example #1: Scala // Scala program of toList() // method import scala.collection.im 1 min read Scala SortedSet sum() method with example The sum() method is utilized to find the sum of all the elements of the SortedSet. Method Definition: def sum: A Return Type: It returns the sum of all the elements of the SortedSet. Example #1: Scala // Scala program of sum() // method // Creating object object GfG { // Main method def main(args:Ar 1 min read Like