Scala Set toMap() method with example Last Updated : 18 Oct, 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 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 { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set((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 // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a set val s1 = Set((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 toMap() method with example R rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Scala-Set +1 More Similar Reads Scala Stack toMap() method with example In Scala Stack class, the toMap() method is utilized to return a map consisting of all the elements of the stack. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the stack. Example #1: Scala // Scala program of toMap() // method // Import 2 min read Scala Set take() method with example The take() method is utilized to return a set consisting of first 'n' elements of the set. Method Definition: def take(n: Int): Set[A] Where 'n' is specifies the number of element to select. Return Type: It returns a set consisting of first 'n' elements of the set. Example #1: Scala // Scala program 1 min read Scala SortedSet toMap() method with example 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 1 min read Scala Set toList() method with example The toList() method is utilized to return a list consisting of all the elements of the set. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the set. Example #1: Scala // Scala program of toList() // method // Creating object object GfG { // Mai 1 min read Scala SortedMap size() method with example The size() is utilized to find the number of key-value pairs in the stated SortedMap. Method Definition: def size: Int Return Type: It returns the number of elements in the SortedMap. Example #1: Scala // Scala program of size() // method import scala.collection.immutable.SortedMap // Creating objec 1 min read Scala Queue toMap() method with example The toMap() method is utilized to return a map consisting of all the elements of the queue. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the queue. Example #1: Scala // Scala program of toMap() // method // Import Queue import scala.co 2 min read Like