Scala Queue clone()方法及示例

Scala Queue clone()方法及示例

clone() 方法是用来创建一个给定队列的副本。

方法定义:defclone():Queue[A]

返回类型。它返回一个新的队列,它是给定队列的一个副本。

例子 #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)

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程