In Scala, scala.collection.mutable implements Stack data structure. The +: method is similar to ++ method in Stack which gives a copy of the stack with an element prepended. Note that the ending operators are right associative.
Method Definition – def +:(elem: A)
Returns – A new stack consisting of elem followed by all elements of this stack.
Stack(1, for, geeks)
List(List(11, 12, 13, 14, 15), 1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.