Java.util.TreeMap.containskey() and containsValue() in Java
There are two variants of contains() in Java.util.TreeMap, both are discussed in this article.
1. containskey(Object o) : It returns true if the map contains a mapping for the specified key.
Parameters: o : The key which will be tested whether present or not. Return Value: Returns true if there is a mapping for the given key. Exception: ClassCastException : This is thrown if the given key cannot be compared with the keys currently in the map. NullPointerException : This is thrown if the specified key is null.
2. containsValue(Object o) : It returns true if this map maps one or more keys to the specified value.
Parameters: o : This is the value whose presence in this map is to be tested. Return Value: Returns true if a mapping to this value exists else false. Exception: NA
This article is contributed by Shambhavi Singh. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.