📜  带有示例的 Scala TreeSet clone() 方法

📅  最后修改于: 2022-05-13 01:54:23.919000             🧑  作者: Mango

带有示例的 Scala TreeSet clone() 方法

在 Scala TreeSet class中, clone()方法用于创建给定 TreeSet 的副本。

示例 #1:

// Scala program of clone() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// 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)
          
    } 
} 
输出:
TreeSet(1, 2, 3, 4, 5)
Clone of the TreeSet: TreeSet(1, 2, 3, 4, 5)

示例 #2:

// Scala program of clone() 
// method 
  
// Import TreeSet
import scala.collection.mutable._
  
// 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)
          
    } 
} 
输出:
TreeSet(a, e, i, o, u)
Clone of the TreeSet: TreeSet(a, e, i, o, u)