Java Hashtable containsValue(Object value) Method Example

The containsValue(Object value) method of java.util.Hashtable class returns true if this hashtable maps one or more keys to this value.

Signature

public boolean containsValue(Object value)

This method returns true if this hashtable maps one or more keys to this value.

Example

The following example shows the usage of java.util.Hashtable.containsValue(value) method.

import java.util.Hashtable;

public class ContainsValueMethodHashtableExample 
{
    public static void main(String args[])
    {
        // create an empty Hashtable
        Hashtable<Integer,String>  hashtable1 = new Hashtable<Integer,String>();
        
        // use put() method to put elements to the Hashtable
        hashtable1.put(1,"Element1");
        hashtable1.put(2,"Element2");
        hashtable1.put(3,"Element3");
        hashtable1.put(4,"Element4");
        hashtable1.put(5,"Element5");
        
        //Check if the hashtable1 contains Value "Element2"
        System.out.println("Does \"hashtable1\" contains value \"Element2\" : "+hashtable1.containsValue("Element2"));
    }
}

Output

Does "hashtable1" contains values "Element2" : true

Leave a Reply

Your email address will not be published. Required fields are marked *