Scala Stack pushAll() method with example
Last Updated :
03 Nov, 2019
In Scala Stack class
, the pushAll() method is utilized to add the elements from a collection to a stack.
Method Definition: def pushAll(elems: IterableOnce[A]): Stack.this.type
Return Type: It returns a stack that contains all the elements of the given collection.
Example #1:
import scala.collection.mutable.Stack
object GfG
{
def main(args : Array[String])
{
var s 1 = Stack[String]()
var s 2 = Set( "C++" , "Java" , "Python" , "Scala" )
println(s 2 )
s 1 .pushAll(s 2 )
println(s 1 )
}
}
|
Output:
Set(C++, Java, Python, Scala)
Stack(Scala, Python, Java, C++)
Example #2:
import scala.collection.mutable.Stack
object GfG
{
def main(args : Array[String])
{
var s 1 = Stack[String]()
var s 2 = Stack( "C++" , "Java" , "Python" , "Scala" )
println(s 2 )
s 1 .pushAll(s 2 )
println(s 1 )
}
}
|
Output:
Stack(C++, Java, Python, Scala)
Stack(Scala, Python, Java, C++)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...