Scala Stack ++ method with example Last Updated : 02 Nov, 2019 Comments Improve Suggest changes Like Article Like Report In Scala, scala.collection.mutable implements Stack data structure. The ++ method gives a new stack with elements from the left hand operand followed by the elements from the right hand operand. Method Definition - def ++[B](that: GenTraversableOnce[B]): Stack[B] Returns - A new stack which contains all elements of this stack followed by all elements of traversable. Example #1: SCALA // Scala program of mutable stack ++() method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a stack val q1 = Stack(1, 2, 3, 4, 5) val q2 = Stack(11, 12, 13, 14, 15) // Applying ++() method val result = q1.++(q2) // Display output print(result) } } Output: Stack(1, 2, 3, 4, 5, 11, 12, 13, 14, 15) Example #2: SCALA // Scala program of mutable stack ++() // method // Import Stack import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a stack val q1 = List(1, 2, 3) val q2 = Stack("for", "geeks") // Applying ++() method val result = q1 ++ q2 // Display output print(result) } } Output: List(1, 2, 3, for, geeks) Comment More infoAdvertise with us Next Article Scala Stack ++ method with example S Shivam_k Follow Improve Article Tags : Python Scala Scala-Method scala-collection Practice Tags : python Similar Reads Scala Stack :+() method with example In Scala, scala.collection.mutable implements Stack data structure. The :+ method is used to create a copy of this stack with an element appended. Method Definition - def :+(elem: A) Returns - a new stack consisting of all elements of this stack followed by elem. Example #1: SCALA // Scala program o 1 min read Scala Stack +:() method with example 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 1 min read Scala Stack ++:() method with example In Scala, scala.collection.mutable implements Stack data structure. The ++: method is similar to ++ method in Stack which gives a new stack with elements from the left hand operand followed by the elements from the right hand operand. But with the difference that in ++:() right operand determines th 2 min read Scala Stack sum() method with example In Scala Stack class, the sum() method is utilized to return the sum of all the elements of the stack. Method Definition: def sum: A Return Type: It returns the sum of all the elements of the stack. Example #1: Scala // Scala program of sum() // method // Import Stack import scala.collection.mutable 1 min read Scala Set ++() method with example The ++() method is utilized to add elements of one set to another set. Method Definition: def ++(elems: A): Set[A] Return Type: It returns a new set containing elements of both the sets. Example #1: Scala // Scala program of ++() // method // Creating object object GfG { // Main method def main(args 1 min read Scala Set +() method with example The +() method is utilized to create a new set with an additional element unless the element is already present. Method Definition: def +(elem: A): Set[A] Return Type: It returns a new set with an additional element unless the element is already present. Example #1: Scala // Scala program of +() // 1 min read Scala Set -() method with example The -() method is utilized to creates a new set with a given element removed from the set. Method Definition: def -(elem: A): Set[A] Return Type: It returns a new set with a given element removed from the set. Example #1: Scala // Scala program of -() // method // Creating object object GfG { // Mai 1 min read Scala Stack foreach() method with example In Scala Stack class, the foreach() method is utilized to apply a given function to all the elements of the stack. Method Definition: def foreach[U](f: (A) => U): Unit Return Type: It returns all the elements of the stack after applying the given function to each of them. Example #1: Scala // Sca 2 min read Scala TreeSet +() method with example In Scala TreeSet class, the +() method is utilized to add an element to the TreeSet unless it is already present. Method Definition: def +(elem: A): TreeSet[A] Return Type: It returns a new TreeSet with an additional element unless the element is already present. Example #1: Scala // Scala program o 2 min read Scala Set sum() method with example The sum() method is utilized to find the sum of all the elements of the set. Method Definition: def sum: A Return Type: It returns the sum of all the elements of the set. Example #1: Scala // Scala program of sum() // method // Creating object object GfG { // Main method def main(args:Array[String]) 1 min read Like