Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Scala Queue clone() method with example

  • Last Updated : 18 Oct, 2019

The clone() method is used to create a copy of the given queue.

Method Definition: defclone(): Queue[A]

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

Example #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)   
          
    
Output:
Queue(10, 11, 12, 13, 14)
Clone of the queue: Queue(10, 11, 12, 13, 14)

Example #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)   
          
    
Output:
Queue(geeks, for, geeks)
Clone of the queue: Queue(geeks, for, geeks)



My Personal Notes arrow_drop_up
Recommended Articles
Page :