Scala immutable TreeSet clone() method

In Scala immutable TreeSet class, the clone() method is used to create a copy of the given TreeSet.

Method Definition: def clone(): Queue[A]

Return Type: It return a new TreeSet which is a copy of the given TreeSet.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of clone() 
// method 
  
// Import TreeSet
import scala.collection.immutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating TreeSet
        val t1 = TreeSet(2, 1, 3, 4, 5
          
        // Print the TreeSet
        println(t1
          
        // Applying clone() method  
        val result = t1.clone
          
        // Displays output 
        println("Clone of the TreeSet: " + result)
          
    

chevron_right


Output:

TreeSet(1, 2, 3, 4, 5)
Clone of the TreeSet: TreeSet(1, 2, 3, 4, 5)

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of clone() 
// method 
  
// Import TreeSet
import scala.collection.immutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating TreeSet
        val t1 = TreeSet("a", "e", "i", "o", "u"
          
        // Print the TreeSet
        println(t1
          
        // Applying clone() method  
        val result = t1.clone
          
        // Displays output 
        println("Clone of the TreeSet: " + result)
          
    

chevron_right


Output:

TreeSet(a, e, i, o, u)
Clone of the TreeSet: TreeSet(a, e, i, o, u)



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.