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

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

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

clone()方法用于创建给定队列的副本。

示例 #1:

// Scala program of clone() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a queue 
        val q1 = Queue(10, 11, 12, 13, 14)
          
        // Print the queue
        println(q1)
          
        // Applying clone() method 
        val q2 = q1.clone()
          
        // Display output
        print("Clone of the queue: " + q2)   
          
    } 
} 
输出:
Queue(10, 11, 12, 13, 14)
Clone of the queue: Queue(10, 11, 12, 13, 14)

示例 #2:

// Scala program of clone() 
// method 
  
// Import Queue  
import scala.collection.mutable._
  
// Creating object 
object GfG 
{ 
  
    // Main method 
    def main(args:Array[String]) 
    { 
        // Creating a queue 
        val q1 = Queue("geeks", "for", "geeks")
          
        // Print the queue
        println(q1)
          
        // Applying clone() method 
        val q2 = q1.clone()
          
        // Display output
        print("Clone of the queue: " + q2)   
          
    } 
} 
输出:
Queue(geeks, for, geeks)
Clone of the queue: Queue(geeks, for, geeks)