Check if a particular value exists in Hashtable in Java

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

Hashtable in Java stores key, value pairs. It implements Map, Cloneable, Serializable. The keys and values cannot be null. The key in Hashtable is hashed, and the resulting hash code is used as the index at which the value is stored within the table. Hashtable is similar to HashMap, but it is synchronized.

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

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