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:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( 10 , 11 , 12 , 13 , 14 )
println(q 1 )
val q 2 = q 1 .clone()
print( "Clone of the queue: " + q 2 )
}
}
|
Output:
Queue(10, 11, 12, 13, 14)
Clone of the queue: Queue(10, 11, 12, 13, 14)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 1 = Queue( "geeks" , "for" , "geeks" )
println(q 1 )
val q 2 = q 1 .clone()
print( "Clone of the queue: " + q 2 )
}
}
|
Output:
Queue(geeks, for, geeks)
Clone of the queue: Queue(geeks, for, geeks)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...