Packages This Package Prev Next Index
public  class  java.util.Hashtable
    extends  java.util.Dictionary  (I-§3.3)
    implements java.lang.Cloneable  (I-§1.22)
{
        // Constructors
    public Hashtable();	§3.4.1
    public Hashtable(int  initialCapacity);	§3.4.2
    public Hashtable(int  initialCapacity, float  loadFactor);	§3.4.3
        // Methods
    public void clear();	§3.4.4
    public Object clone();	§3.4.5
    public boolean contains(Object  value);	§3.4.6
    public boolean containsKey(Object  key);	§3.4.7
    public Enumeration elements();	§3.4.8
    public Object get(Object  key);	§3.4.9
    public boolean isEmpty();	§3.4.10
    public Enumeration keys();	§3.4.11
    public Object put(Object  key, Object  value);	§3.4.12
    protected void rehash();	§3.4.13
    public Object remove(Object  key);	§3.4.14
    public int size();	§3.4.15
    public String toString();	§3.4.16
}
This class implements a hash table, which maps keys to values. Any non-null object can be 
used as a key or as a value.
To successfully store and retrieve objects from a hash table, the objects used as keys must implement the hashCode method (I-§1.12.6) and the equals method (I-§1.12.3).
An instance of Hashtable has two parameters that affect its efficiency: its capacity and its load factor. The load factor should be between 0.0 and 1.0. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is increased by calling the rehash method (I-§3.4.13). Larger load factors use memory more efficiently, at the expense of larger expected time per lookup.
This example creates a hashtable of numbers. It uses the names of the numbers as keys:
Hashtable  numbers  =  new  Hashtable();
numbers.put("one",  new  Integer(1));
numbers.put("two",  new  Integer(2));
numbers.put("three",  new  Integer(3));
Integer  n  =  (Integer)numbers.get("two");
if  (n  !=  null)  {
        System.out.println("two  =  "  +  n);
}
public Hashtable()
public Hashtable(int  initialCapacity)
initialCapacity
- the initial capacity of the hash table
public
Hashtable(int  initialCapacity, float  loadFactor)
initialCapacity
- the initial size of the hashtable
loadFactor
- a number between 0.0 and 1.0,
public void clear()
public Object clone()
public boolean contains(Object  value)
value
- a value to search for
public boolean containsKey(Object  key)
key
- possible key
public Enumeration elements()
public Object get(Object  key)
key
- a key in the hash table
public boolean isEmpty()
public Enumeration keys()
public Object put(Object  key, Object  value)
key
- the hashtable key
value
- the value
protected void rehash()
public Object remove(Object  key)
key
- the key that needs to be removed
public int size()
public String toString()
Packages This Package Prev Next IndexJava API Document (HTML generated by dkramer on April 22, 1996)