Scala Mutable SortedMap take() method with example Last Updated : 04 May, 2020 Comments Improve Suggest changes Like Article Like Report The take() method is utilized to select the first 'n' elements of the SortedMap. Method Definition: def take(n: Int): SortedMap[A, B] Return Type: It returns the first 'n' elements of the SortedMap. Example #1: Scala // Scala program of take() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap(3 -> "geeks", 4 -> "for", 2 -> "cs") // Applying take method val result = m1.take(2) // Displays output println(result) } } Output: Map(2 -> cs, 3 -> geeks) Example #2: Scala // Scala program of take() // method import scala.collection.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap(3 -> "geeks", 4 -> "for", 2 -> "cs") // Applying take method val result = m1.take(4) // Displays output println(result) } } Output: Map(2 -> cs, 3 -> geeks, 4 -> for) Comment More infoAdvertise with us Next Article Scala Mutable SortedMap take() method with example S Shivam_k Follow Improve Article Tags : Python Scala Scala Mutable-collections Scala Mutable-SortedMap Practice Tags : python Similar Reads Scala Mutable SortedMap tail() method with example The tail() method is utilized to display all the elements of the SortedMap except the first one. Method Definition: def tail: SortedMap[A, B] Return Type: It returns all the elements of the stated SortedMap except the first one. Example #1: Scala // Scala program of tail() // method import scala.col 1 min read Scala Mutable SortedMap takeRight() method with example The takeRight() method is utilized to select the last 'n' elements of the SortedMap. Method Definition: def takeRight(n: Int): SortedMap[A, B] Return Type: It returns the last 'n' elements of the SortedMap. Example #1: Scala // Scala program of takeRight() // method import scala.collection.SortedMap 1 min read Scala Mutable SortedMap toSeq() method with example The toSeq() method is utilized to display a sequence from the Scala SortedMap. Method Definition: def toSeq: Seq[A] Return Type: It returns a sequence from the stated SortedMap. Example #1: Scala // Scala program of toSeq() // method import scala.collection.SortedMap // Creating object object GfG { 1 min read Scala Mutable SortedMap toSet() method with example The toSet() method is utilized to display a set from the Scala SortedMap. Method Definition: def toSet: Set[A] Return Type: It returns a set from the stated SortedMap. Example #1: Scala // Scala program of toSet() // method import scala.collection.SortedMap // Creating object object GfG { // Main me 1 min read Scala Mutable SortedMap toArray() method with example The toArray() method is utilized to display an array from the Scala SortedMap. Method Definition: def toArray: Array[(A, B)] Return Type: It returns an array from the stated SortedMap. Example #1: Scala // Scala program of toArray() // method import scala.collection.SortedMap // Creating object obje 1 min read Like