Scala immutable TreeSet toMap() method Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In Scala immutable TreeSet class the toMap() method is utilised to return a map consisting of all the elements of the TreeSet. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toMap() // method // Import TreeSet import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet((1, 2), (3, 4), (5, 6)) // Print the TreeSet println(t1) // Applying toMap method val result = t1.toMap // Display output print("Elements in the Map: " + result) } } Output: TreeSet((1, 2), (3, 4), (5, 6)) Elements in the Map: Map(1 -> 2, 3 -> 4, 5 -> 6) Example #2: Scala // Scala program of toMap() // method // Import TreeSet import scala.collection.immutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating TreeSet val t1 = TreeSet(("u", "a"), ("i", "o"), ("e", "f")) // Print the TreeSet println(t1) // Applying toMap method val result = t1.toMap // Display output print("Elements in the Map: " + result) } } Output: TreeSet((e, f), (i, o), (u, a)) Elements in the Map: Map(e -> f, i -> o, u -> a) Comment More infoAdvertise with us Next Article Scala immutable TreeSet -() method S Shivam_k Follow Improve Article Tags : Scala Scala immutable-TreeSet Similar Reads Scala immutable TreeSet take() method In Scala immutable TreeSet class the take() method is utilized to return a TreeSet consisting of the first ânâ elements of the TreeSet. Method Definition: def take(n: Int): TreeSet[A] Return Type: It returns a TreeSet consisting of the first ânâ elements of the TreeSet. Example #1: Scala // Scala pr 1 min read Scala immutable TreeSet toSeq() method In Scala immutable TreeSet class the toSeq() method is utilised to return a seq consisting of all the elements of the TreeSet. Method Definition: def toSeq: Seq[A] Return Type: It returns a seq consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toSeq() // method // 2 min read Scala immutable TreeSet toArray() method In Scala immutable TreeSet class the toArray() is utilised to return an array consisting of all the elements of the TreeSet. Method Definition: def toArray: Array[A] Return Type: It returns an array consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toArray() // met 2 min read Scala immutable TreeSet --() method In Scala immutable TreeSet class, the --() method is utilised to subtract elements of one TreeSet to another TreeSet. Method Definition: def --(that: IterableOnce[A]): TreeSet[A] Return Type: It returns a new TreeSet which contains the element from A - B TreeSets. Example #1: Scala // Scala program 2 min read Scala immutable TreeSet -() method In Scala immutable TreeSet class, the -() method is utilized to remove an element from the given TreeSet. Method Definition: def -(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an element removed from the given TreeSet. Example #1: Scala // Scala program of -() // method // Import 1 min read Scala immutable TreeSet +() method In Scala immutable TreeSet class, the +() method is utilised to add an element to the TreeSet unless it is already present. Method Definition: def +(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an additional element unless the element is already present. Example #1: Scala // Scala 2 min read Like