![]() |
VOOZH | about |
In Java, the containsValue() method of the HashMap class is used to check whether a particular value is being mapped by a single or more than one key in the HashMap.
Example 1: This example demonstrates how the containsValue() method works when String values are mapped to integer keys.
Initial Mappings are: {1=Geeks, 2=For, 3=Geeks}
Is the value 'Geeks' present? true
Is the value 'Java' present? false
public boolean containsValue(Object value)
Example 2: This example shows how the containsValue() method works when integer values are mapped to string keys.
Initial Mappings are: {Geeks=3, For=2}
Is the value '1' present? false
Is the value '3' present? true
Note: In HashMap if you add duplicate key, the value associated with that key gets update and the previous value is removed.