Check if a particular value exists in HashMap in Java

In this tutorial, we will learn how to Check if a particular value exists in HashMap in Java ?

HashMap in Java is a hash table based implementation of Map Interface. HashMap extends AbstractMap and implements Serializable, Cloneable and Map interfaces. It is used to store key-value pairs. HashMap is a widely used collection classes in java.  To access a value in HashMap, you need to have a key.

To check if a particular value exists in HashMap or not, HashMap class in Java provides a method containsValue(). We will use this method to check if particular value exists in HashMap. The syntax of this method is:

Syntax of containsValue() method:

Parameters:
value – The value whose presence in this map is to be tested.

Returns:
true if the value exists in map.

Example:

 

Output:

 

Related posts

Leave a Comment