Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Scala TreeSet toSeq() method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The toSeq() method is utilized 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 program of toSeq() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// 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 program of toSeq() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// 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

My Personal Notes arrow_drop_up
Last Updated : 11 Nov, 2019
Like Article
Save Article
Similar Reads