Scala Map take() method with example Last Updated : 13 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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:Array[String]) { // Creating a map val m1 = Map(3 -> "geeks", 4 -> "for", 2 -> "cs") // Applying take method val result = m1.take(2) // Displays output println(result) } } Output: Map(3 -> geeks, 4 -> for) Example #2: Scala // Scala program of take() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a map val m1 = Map(3 -> "geeks", 4 -> "for", 2 -> "cs") // Applying take method val result = m1.take(4) // Displays output println(result) } } Output: Map(3 -> geeks, 4 -> for, 2 -> cs) Comment More infoAdvertise with us Next Article Scala List take() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Scala-Map Similar Reads Scala Map takeRight() method with example The takeRight() method is utilized to select the last 'n' elements of the map. Method Definition: def takeRight(n: Int): Map[A, B] Return Type: It returns the last 'n' elements of the map. Example #1: Scala // Scala program of takeRight() // method // Creating object object GfG { // Main method def 1 min read Scala List take() method with example The take() method belongs to the value member of the class List. It is utilized to take the first n elements from the list. Method Definition: deftake(n: Int): List[A] Where, n is the number of elements to be taken from the list. Return Type:It returns a list containing only the first n elements fro 1 min read Scala Set take() method with example The take() method is utilized to return a set consisting of first 'n' elements of the set. Method Definition: def take(n: Int): Set[A] Where 'n' is specifies the number of element to select. Return Type: It returns a set consisting of first 'n' elements of the set. Example #1: Scala // Scala program 1 min read Scala Iterator take() method with example The take() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to select the first n elements of the stated iterator. Method Definition: def take(n: Int): Iterator[A] Where, n is the number of element to take from the given iterator. Return Type: It returns the 2 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 Queue take() method with example The take() method is utilized to return a queue consisting of the first ânâ elements of the queue. Method Definition: def take(n: Int): Queue[A] Return Type: It returns a queue consisting of the first ânâ elements of the queue. Example #1: Scala // Scala program of take() // method // Import Queue i 1 min read Like