You are on page 1of 3

HASHTABLE

•Java Hashtable class implements a hashtable, which maps keys to values.


•It inherits Dictionary class and implements the Map interface.
•A Hashtable is an array of a list, it contains values based on the key & contains only
unique elements.
•HashTable is thread safe and synchronized, it should be used in multithreading
applications. 
•It doesn't allow null keys and null values in the HashTable object. Preferred when thread
synchronization is needed.
•HashTable is the only class other than vector which uses the enumerator to iterate the
values of HashTable object, the enumerations returned by the Hashtable keys and
elements methods are not fail fast.
•Default capacity is 11 and load factor is 0.75.
DIFFERENCES BETWEEN HASHMAP AND
HASHTABLE
EXAMPLE PROGRAM TO IMPLEMENT HASHTABLE

Package assignment;
import java.util.*;

class TestingCollectionHashTable
{
public static void main(String args[])
{
Hashtable<Integer, String> hash=new Hashtable<Integer, String>();

hash.put(101,"Amit");
hash.put(101,"Aman");
hash.put(102,"Vikram");
hash.put(103,"Vinay");

for (Map.Entry map:hash.entrySet())


{
System.out.println(map.getKey()+" "+map.getValue());
}
}
}

You might also like