Scala Queue map() method with example Last Updated : 29 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The map() method is utilized to build a new queue by applying a function to all elements of this queue. Method Definition: def map[B](f: (A) => B): Queue[B] Return Type: It returns a new queue containing all the elements after applying the given function. Example #1: Scala // Scala program of map() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a queue val q1 = Queue(1, 3, 2, 7, 6, 5) // Print the queue println(q1) // Applying map method val result = q1.map(x => x*x) // Display output print("New queue after squaring all elements: " + result) } } Output: Queue(1, 3, 2, 7, 6, 5) New queue after squaring all elements: Queue(1, 9, 4, 49, 36, 25) Example #2: Scala // Scala program of map() // method // Import Queue import scala.collection.mutable._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a queue val q1 = Queue(1, 3, 2, 7, 6, 5) // Print the queue println(q1) // Applying map method val result = q1.map(x => x/2) // Display output print("New queue after dividing all elements by 2: " + result) } } Output: Queue(1, 3, 2, 7, 6, 5) New queue after dividing all elements by 2: Queue(0, 1, 1, 3, 3, 2) Comment More infoAdvertise with us Next Article Scala Queue map() method with example rupesh_rao Follow Improve Article Tags : Scala Scala Scala-Method scala-collection Similar Reads Scala Map remove() method with example The remove() method is utilized to remove a key from the map and return its value only. Method Definition: def remove(key: A): Option[B] Return Type: It returns the value of the key present in the above method as argument. Example #1: Scala // Scala program of remove() // method // Creating object o 1 min read Scala Map min() method with example The min() method is utilized to find the smallest element of the map. Method Definition: def min: (A, B) Return Type: It returns the smallest element of the map. Example #1: Scala // Scala program of min() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Cre 1 min read Scala Map retain() method with example The retain() method is utilized to retain all the pairs of the map that satisfies the stated condition. Method Definition: def retain(p: (A, B) => Boolean): Map.this.type Return Type: It returns all the "key-value" pairs of the map which satisfies the stated predicate. Example #1: Scala // Scala 1 min read Scala Queue toMap() method with example The toMap() method is utilized to return a map consisting of all the elements of the queue. Method Definition: def toMap[T, U]: Map[T, U] Return Type: It returns a map consisting of all the elements of the queue. Example #1: Scala // Scala program of toMap() // method // Import Queue import scala.co 2 min read Scala Set map() method with example The map() method is utilized to build a new set by applying a function to all elements of this set. Method Definition: def map[B](f: (A) => B): immutable.Set[B] Return Type: It returns a new set containing all the elements after applying the given function. Example #1: Scala // Scala program of m 1 min read Scala Map get() method with example The get() method is utilized to give the value associated with the keys of the map. The values are returned here as an Option i.e, either in form of Some or None. Method Definition:def get(key: A): Option[B] Return Type: It returns the keys corresponding to the values given in the method as argument 2 min read Scala Map max() method with example The max() method is utilized to find the largest element of the map. Method Definition: def max: (A, B) Return Type: It returns the largest element of the map. Example #1: Scala // Scala program of max() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creat 1 min read Scala List map() method with example The map() method is utilized to apply the stated function to all the elements of the list. Method Definition: def map[B](f: (A) => B): List[B] Return Type: It returns a new list after applying the stated function to all the elements of the list. Example #1: Scala // Scala program of map() // meth 1 min read Scala Map take() method with example The take() method is utilized to select the first 'n' elements of the map. Method Definition: def take(n: Int): Map[A, B] Return Type: It returns the first 'n' elements of the map. Example #1: Scala // Scala program of take() // method // Creating object object GfG { // Main method def main(args:Arr 1 min read Scala Map init() method with example The init() method is utilized to delete the last element of the map. It will return all the elements of the Map except the last one. Method Definition: def init: Map[A, B] Return Type: It returns all the elements of the map except the last one. Example #1: Scala // Scala program of init() // method 1 min read Like