VOOZH about

URL: https://www.geeksforgeeks.org/java/hashmap-containsvalue-method-in-java/

⇱ Java HashMap containsValue() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java HashMap containsValue() Method

Last Updated : 11 Jul, 2025

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.


Output
Initial Mappings are: {1=Geeks, 2=For, 3=Geeks}
Is the value 'Geeks' present? true
Is the value 'Java' present? false

Syntax of containsValue() Method

public boolean containsValue(Object value)

  • Parameter: The value whose presence is to be checked in the HashMap.
  • Return Type: This method returns True if the HashMap contains at least one mapping with the specified value, otherwise returns False

Example 2: This example shows how the containsValue() method works when integer values are mapped to string keys.


Output
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.

Comment