Scala SortedMap count() method with example Last Updated : 02 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The count() method is utilized to count pair of keys in the SortedMap. Method Definition: def count(p: ((A, B)) => Boolean): Int Return Type: It returns the number of keys present in the SortedMap that satisfies the given predicate. Example #1: Scala // Scala program of count() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 5) // Applying count method val result = m1.count(z=>true) // Displays output println(result) } } Output: 3 Example #2: Scala // Scala program of count() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 5) // Applying count method val result = m1.count(z=>true) // Displays output println(result) } } Output: 2 So, the identical keys are counted only once. Comment More infoAdvertise with us Next Article Scala SortedMap count() method with example gopaldave Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala SortedSet count() method with example The count() method is utilized to count the number of elements in the SortedSet. Method Definition: def count(p: (A) => Boolean): Int Return Type: It returns the number of elements present in the SortedSet. Example #1: Scala // Scala program of count() // method import scala.collection.immutable. 1 min read Scala Mutable SortedMap count() method with example The count() method is utilized to count pair of keys in the SortedMap. Method Definition: def count(p: ((A, B)) => Boolean): Int Return Type: It returns the number of keys present in the SortedMap that satisfies the given predicate. Example #1: Scala // Scala program of count() // method import s 1 min read Scala SortedMap drop() method with example The drop() method is utilized to delete the first 'n' elements. Method Definition: def drop(n: Int): SortedMap[A, B] Return Type: It returns all the elements of the SortedMap except the first 'n' elements. Example #1: Scala // Scala program of drop() // method import scala.collection.immutable.Sorte 1 min read Scala Stack count() method with example In Scala Stack class, the count() method is utilized to count the number of elements in the stack that satisfies a given predicate. Method Definition: def count(p: (A) => Boolean): Int Return Type: It returns the count the number of elements in the stack that satisfies a given predicate. Example 2 min read Scala SortedMap empty() method with example The empty() method is utilized to make the SortedMap empty. Method Definition: def empty: SortedMap[A, B] Return Type: It returns an empty SortedMap. Example #1: Scala // Scala program of empty() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def 1 min read Scala Set count() method with example The count() method is utilized to count the number of elements in the set. Method Definition: def count(p: (A) => Boolean): Int Return Type: It returns the number of elements present in the set. Example #1: Scala // Scala program of count() // method // Creating object object GfG { // Main method 1 min read Scala SortedMap copyToArray() method with example The copyToArray() method is utilized in copying pair of keys of the SortedMap to an Array. Method Definition: def copyToArray(xs: Array[(A, B)]): Unit Return Type: It returns the keys of the SortedMap to an array. Example #1: Scala // Scala program of copyToArray() // method import scala.collection. 2 min read Scala SortedMap equals() method with example The equals() method is utilized to check whether the two SortedMaps have the same key-values pair or not. Method Definition: def equals(that: Any): Boolean Return Type: It returns true if the key-value pairs of both the SortedMaps are same else it returns false. Example #1: Scala // Scala program of 1 min read Scala SortedMap apply() method with example The apply() is utilized to search a key in the stated SortedMap. Method Definition: m1.apply("key") Here m1 is SortedMap. Return Type: It returns the value of the key to be searched. Example #1: Scala // Scala program of apply() // method import scala.collection.immutable.SortedMap // Creating objec 1 min read Scala SortedMap get() method with example The get() method is utilized to give the value associated with the keys of the SortedMap. 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 ar 2 min read Like