Hashtable Class

Hashtable
  • The underlying data structure is Hashtable
  • Insertion order is not preserved and it is based on hash code of the keys.
  • Heterogeneous objects are allowed for both keys and values.
  • null key (or) null value is not allowed otherwise we will get NullPointerException.
  • Duplicate keys are allowed but values can be duplicated.
  • Every method present inside Hashtable is syncronized and hence Hashtable object is Thread-safe.
Constructors

1. Hashtable h=new Hashtable();

Creates an empty Hashtable object with default initialcapacity 11 and default fill ratio 0.75.

2. Hashtable h=new Hashtable(int initialcapacity);

3. Hashtable h=new Hashtable(int initialcapacity,float fillratio);

4. Hashtable h=new Hashtable (Map m);

package com.ashok.collections;

import java.util.Hashtable;

/**
 * 
 * @author ashok.mariyala
 *
 */
public class MyHashTable {
   public static void main(String[] args) {
      Hashtable hashtable = new Hashtable();

      hashtable.put("Key1", "Ashok");
      hashtable.put("Key2", "Vinod");
      hashtable.put("Key3", "Dillesh");
      hashtable.put("Key4", "Naresh");
      hashtable.put("Key5", "Thiru");

      System.out.println(hashtable);
   }
}
Hashtable Class


Scroll to top