Scala Stack clone() method with example
Last Updated :
03 Nov, 2019
In Scala Stack class
, the clone() method is used to create a copy of the given stack.
Method Definition: def clone(): Stack[A]
Return Type: It return a new stack which is a copy of the given stack.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 1 , 2 , 3 , 4 , 5 )
println(s 1 )
val result = s 1 .clone
print( "Clone of the stack: " + result)
}
}
|
Output:
Stack(1, 2, 3, 4, 5)
Clone of the stack: Stack(1, 2, 3, 4, 5)
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 3 , 4 , 5 , 6 , 7 , 8 )
println(s 1 )
val result = s 1 .clone
print( "Clone of the stack: " + result)
}
}
|
Output:
Stack(3, 4, 5, 6, 7, 8)
Clone of the stack: Stack(3, 4, 5, 6, 7, 8)
Share your thoughts in the comments
Please Login to comment...