Scala immutable TreeSet toSeq() method Last Updated : 19 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 // 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 toSeq method val result = t1.toSeq // Display output print("Elements in the Seq: ") for (ele <- result) print(ele + " ") } } Output: TreeSet(1, 2, 3, 4, 5, 6) Elements in the Seq: 1 2 3 4 5 6 Example #2: Scala // Scala program of toSeq() // 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 toSeq method val result = t1.toSeq // Display output print("Elements in the Seq: ") for (ele <- result) print(ele + " ") } } Output: TreeSet(a, e, i, o, u) Elements in the Seq: a e i o u Comment More infoAdvertise with us Next Article Scala immutable TreeSet toList() 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 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 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 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 Scala immutable TreeSet toString() method 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 // I 2 min read Scala immutable TreeSet toBuffer() method In Scala immutable TreeSet class the toBuffer() method is utilized to return a buffer consisting of all the elements of the TreeSet. Method Definition: def toBuffer[B >: A]: Buffer[B] Return Type: It returns a buffer consisting of all the elements of the TreeSet. Example #1: Scala // Scala progra 2 min read Like