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 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. 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 value val q1 = 1 val q2 = Stack("for", "geeks") // Applying +:() method val result = q1 +: q2 // Display output print(result) } } Output: Stack(1, for, geeks) 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 ) val q2 = List(11, 12, 13, 14, 15) // Applying ++() method val result = q1.+:(q2) // Display output print(result) } } Output: List(List(11, 12, 13, 14, 15), 1) 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 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 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 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 ++ 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 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 Stack map() method with example In Scala Stack class, the map() method is utilized to build a new stack by applying a function to all elements of the given stack. Method Definition: def map[B](f: (A) => B): Stack[B] Return Type: It returns a new stack containing all the elements after applying the given function. Example #1: Sc 2 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 Like