Scala immutable TreeSet toString() method Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In Scala immutable TreeSet class the toString() method is utilised to return a string representation of the TreeSet object. Method Definition: def toString(): String Return Type: It returns a string representation of the TreeSet object. Example #1: Scala // Scala program of toString() // 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 toString method val result = t1.toString // Display output print("String representation of the TreeSet object: " + result) } } Output: TreeSet(1, 2, 3, 4, 5, 6) String representation of the TreeSet object: TreeSet(1, 2, 3, 4, 5, 6) Example #2: Scala // Scala program of toString() // 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") // Print the TreeSet println(t1) // Applying toString method val result = t1.toString // Display output print("String representation of the TreeSet object: " + result) } } Output: TreeSet(a, e, i, o, u) String representation of the TreeSet object: TreeSet(a, e, i, o, u) Comment More infoAdvertise with us Next Article Scala immutable TreeSet size() method S Shivam_k Follow Improve Article Tags : Scala Scala immutable-TreeSet Similar Reads Scala immutable TreeSet toList() method In Scala immutable TreeSet class the toList() method is utilised to return a list consisting of all the elements of the TreeSet. Method Definition: def toList: List[A] Return Type: It returns a list consisting of all the elements of the TreeSet. Example #1: Scala // Scala program of toList() // meth 2 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 takeRight() method In Scala immutable TreeSet class the takeRight() method is utilised to return a TreeSet consisting of the last ânâ elements of the TreeSet. Method Definition: def takeRight(n: Int):TreeSet[A] Return Type: It returns a TreeSet consisting of the last ânâ elements of the TreeSet. Example #1: Scala // S 1 min read Scala immutable TreeSet size() method In Scala immutable TreeSet class the size() method is utilised to return the number of elements present in the TrreSet. Method Definition: def size: Int Return Type: It returns the number of elements present in the TreeSet. Example #1: Scala // Scala program of size() // method // Import TreeSet imp 1 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 toMap() method 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() // m 2 min read Like