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 Map interface of Scala. It checks whether the stated map contains a binding for a key or not.
def contains(key: K): Boolean
Where, k is the key.
It returns true if there is a binding for the key in the map stated else returns false.
Here, contains method has a key identical to the key present in the map stated above so, it returns true.
Here, contains method has a key which is not identical to the key present in the map stated above so, it returns false.
- Scala | map() method
- Scala Iterator next() method with example
- Scala Iterator max() method with example
- Scala | unapplySeq() method
- Method Overloading in Scala
- Method Overriding in Scala
- Scala Iterator min() method with example
- Scala | flatMap Method
- Scala Iterator sum() method with example
- Scala Iterator seq() method with example
- Scala | Method Invocation
- Scala map isDefinedAt() method with example
- Parameterless Method in Scala
- Scala Iterator length() method with example
- Scala Iterator isTraversableAgain() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.