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 and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- HashMap containsValue() Method in Java
- Hashtable containsValue() Method in Java
- TreeMap containsValue() Method in Java
- EnumMap containsValue(value) method in Java
- WeakHashMap containsValue() Method in Java
- IdentityHashMap containsValue() Method in Java
- ConcurrentHashMap containsValue() Method in Java
- AbstractMap containsValue() Method in Java with Examples
- Map containsValue() method in Java with Examples
- ConcurrentSkipListMap containsValue() method in Java with Examples
- Properties containsValue(value) method in Java with Examples
- Java.util.TreeMap.descendingMap() and descendingKeyset() in Java
- Java.util.TreeMap.firstEntry() and firstKey() in Java
- Java.util.TreeMap.pollFirstEntry() and pollLastEntry() in Java
- Java.util.TreeMap.put() and putAll() in Java
- Java.util.TreeMap.floorEntry() and floorKey() in Java
- Java Swing | Translucent and shaped Window in Java
- Difference between Core Java and Advanced Java
- Difference between a Java Application and a Java Applet
- Difference between Java IO and Java NIO