Java Hashtable hashCode() Example

The hashCode() method of java.util.Hashtable class returns the hash code value for this Map as per the definition in the Map interface.

Signature

public int hashCode()

This method returns the hash code value for this Map as per the definition in the Map interface.

Example

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

import java.util.Hashtable;

public class HashCodeMethodHashtableExample 
{
    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");
        
        //Get the hashcode of hashtable1
        System.out.println("HashCode of the Hashtable \"hashtable1\" is :"+hashtable1.hashCode());
    }
}

Output

HashCode of the Hashtable "hashtable1" is :281524276

Leave a Reply

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