Scala SortedMap contains() method with example Last Updated : 02 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The contains() method of Scala is equivalent to the isDefinedAt method of Scala but the only difference is that isDefinedAt is observed on all the PartialFunction classes while contains is clearly defined to the SortedMap interface of Scala. It checks whether the stated SortedMap contains a binding for a key or not. Method Definition: def contains(key: K): Boolean Where, k is the key. Return Type: It returns true if there is a binding for the key in the SortedMap stated else returns false. Example #1: Scala // Scala program of contains() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap(3 -> "geeks", 4 -> "for", 4 -> "for") // Applying contains method val result = m1.contains(3) // Displays output println(result) } } Output: true Here, contains method has a key identical to the key present in the SortedMap stated above so, it returns true. Example #2: Scala // Scala program of contains() // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap(3 -> "geeks", 4 -> "for", 4 -> "for") // Applying contains method val result = m1.contains(5) // Displays output println(result) } } Output: false Here, contains method has a key which is not identical to the key present in the SortedMap stated above so, it returns false. Comment More infoAdvertise with us Next Article Scala SortedMap contains() method with example G gopaldave Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala 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 SortedSet contains() method with example The contains() method is utilized to check if an element is present in the SortedSet of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the SortedSet else it returns false. Example #1: Scala // Scala program of contains() // method imp 1 min read Scala Mutable SortedMap contains() method with example The contains() method of Scala is equivalent to the isDefinedAt method of Scala but the only difference is that isDefinedAt is observed on all the PartialFunction classes while contains is clearly defined to the SortedMap interface of Scala. It checks whether the stated SortedMap contains a binding 2 min read Scala Set contains() method with example The contains() method is utilized to check if an element is present in the set of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the set else it returns false. Example #1: Scala // Scala program of contains() // method // Creating obj 1 min read Scala Stack contains() method with example In Scala Stack class, the contains() method is utilized to check if an element is present in the stack of not. Method Definition: def contains(elem: A): Boolean Return Type: It returns true if the element is present in the stack or else it returns false. Example #1: Scala // Scala program of contain 1 min read Like