Register Now


Lost Password

Enter your email to reset your password.

BY Author

Java – Hashtable


class Hashtable<K, V>

Hashtable extends abstract class Dictionary & implements the Map interface.

It is similar to the HashMap class, but it is synchronized.

It works with data structure known as hash-table.

Elements insertion order is not preserved.

Null is not allowed for both key & value.

List of HashTable Constructors (CLICK HERE)

List of HashTable Methods (CLICK HERE)


 import java.util.Hashtable;
 import java.util.Map.Entry;

 class HashTableDemo 
     public static void main(String args[])
         Hashtable<Integer, String> ht = new Hashtable<Integer, String>();
         ht.put(1, "Roger");
         ht.put(5, "Jennifer");
         ht.put(2, "Jack");
         ht.put(4, "James");
         ht.put(3, "Ricky");
         for(Entry<Integer, String> me:ht.entrySet())
             System.out.println(me.getKey()+" "+me.getValue());  


5 Jennifer
4 James
3 Ricky
2 Jack
1 Roger


Leave a reply