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 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 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 q2 = List(11, 12, 13, 14, 15) // Applying :+() method val result = q2 :+ 100 // Display output print(result) } } Output: List(11, 12, 13, 14, 15, 100) 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]) { val st1 = Stack(1, 2, 3) val st2 = Stack("Geeks", "For") // Applying :+() method val result1 = st2 :+ st1 // Display output print(result1) } } Output: Stack(Geeks, For, Stack(1, 2, 3)) Comment More infoAdvertise with us Next Article Scala Stack :+() method with example S Shivam_k Follow Improve Article Tags : Scala Scala-Method scala-collection Similar Reads 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 ++ method with example 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 1 min read Scala Stack :() method with example In Scala, scala.collection.mutable implements Stack data structure. The :\ method applies a binary operator to a start value and all elements of this traversable or iterator, going right to left. Method Definition - def :\[B](z: B)(op: (A, B) ? B): B Returns - the result of inserting op between cons 1 min read Scala Stack /:() method with example In Scala, scala.collection.mutable implements Stack data structure. The /: method applies a binary operator to a start value and all elements of this traversable or iterator, going left to right. Method Definition - def /:[B](z: B)(op: (B, A) ? B): B Returns - the result of inserting op between cons 1 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 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 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 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 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 Like