public class

Hashtable

extends Dictionary<K, V>
implements Serializable Cloneable Map<K, V>
java.lang.Object
   ↳ java.util.Dictionary<K, V>
     ↳ java.util.Hashtable<K, V>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Hashtable is a synchronized implementation of Map. All optional operations are supported.

Neither keys nor values can be null. (Use HashMap or LinkedHashMap if you need null keys or values.)

See Also

Summary

Public Constructors
Hashtable()
Constructs a new Hashtable using the default capacity and load factor.
Hashtable(int capacity)
Constructs a new Hashtable using the specified capacity and the default load factor.
Hashtable(int capacity, float loadFactor)
Constructs a new Hashtable using the specified capacity and load factor.
Hashtable(Map<? extends K, ? extends V> map)
Constructs a new instance of Hashtable containing the mappings from the specified map.
Public Methods
synchronized void clear()
Removes all key/value pairs from this Hashtable, leaving the size zero and the capacity unchanged.
synchronized Object clone()
Returns a new Hashtable with the same key/value pairs, capacity and load factor.
boolean contains(Object value)
Returns true if this Hashtable contains the specified object as the value of at least one of the key/value pairs.
synchronized boolean containsKey(Object key)
Returns true if this Hashtable contains the specified object as a key of one of the key/value pairs.
synchronized boolean containsValue(Object value)
Searches this Hashtable for the specified value.
synchronized Enumeration<V> elements()
Returns an enumeration on the values of this Hashtable.
synchronized Set<Entry<K, V>> entrySet()
Returns a set of the mappings contained in this Hashtable.
synchronized boolean equals(Object object)
Compares this Hashtable with the specified object and indicates if they are equal.
synchronized V get(Object key)
Returns the value associated with the specified key in this Hashtable.
synchronized int hashCode()
Returns an integer hash code for this object.
synchronized boolean isEmpty()
Returns true if this Hashtable has no key/value pairs.
synchronized Set<K> keySet()
Returns a set of the keys contained in this Hashtable.
synchronized Enumeration<K> keys()
Returns an enumeration on the keys of this Hashtable instance.
synchronized V put(K key, V value)
Associate the specified value with the specified key in this Hashtable.
synchronized void putAll(Map<? extends K, ? extends V> map)
Copies every mapping to this Hashtable from the specified map.
synchronized V remove(Object key)
Removes the key/value pair with the specified key from this Hashtable.
synchronized int size()
Returns the number of key/value pairs in this Hashtable.
synchronized String toString()
Returns the string representation of this Hashtable.
synchronized Collection<V> values()
Returns a collection of the values contained in this Hashtable.
Protected Methods
void rehash()
Increases the capacity of this Hashtable.
[Expand]
Inherited Methods
From class java.util.Dictionary
From class java.lang.Object
From interface java.util.Map

Public Constructors

public Hashtable ()

Since: API Level 1

Constructs a new Hashtable using the default capacity and load factor.

public Hashtable (int capacity)

Since: API Level 1

Constructs a new Hashtable using the specified capacity and the default load factor.

Parameters
capacity the initial capacity.

public Hashtable (int capacity, float loadFactor)

Since: API Level 1

Constructs a new Hashtable using the specified capacity and load factor.

Parameters
capacity the initial capacity.
loadFactor the initial load factor.

public Hashtable (Map<? extends K, ? extends V> map)

Since: API Level 1

Constructs a new instance of Hashtable containing the mappings from the specified map.

Parameters
map the mappings to add.

Public Methods

public synchronized void clear ()

Since: API Level 1

Removes all key/value pairs from this Hashtable, leaving the size zero and the capacity unchanged.

See Also

public synchronized Object clone ()

Since: API Level 1

Returns a new Hashtable with the same key/value pairs, capacity and load factor.

Returns
  • a shallow copy of this Hashtable.
See Also

public boolean contains (Object value)

Since: API Level 1

Returns true if this Hashtable contains the specified object as the value of at least one of the key/value pairs.

Parameters
value the object to look for as a value in this Hashtable.
Returns
  • true if object is a value in this Hashtable, false otherwise.

public synchronized boolean containsKey (Object key)

Since: API Level 1

Returns true if this Hashtable contains the specified object as a key of one of the key/value pairs.

Parameters
key the object to look for as a key in this Hashtable.
Returns
  • true if object is a key in this Hashtable, false otherwise.

public synchronized boolean containsValue (Object value)

Since: API Level 1

Searches this Hashtable for the specified value.

Parameters
value the object to search for.
Returns
  • true if value is a value of this Hashtable, false otherwise.

public synchronized Enumeration<V> elements ()

Since: API Level 1

Returns an enumeration on the values of this Hashtable. The results of the Enumeration may be affected if the contents of this Hashtable are modified.

Returns
  • an enumeration of the values of this Hashtable.

public synchronized Set<Entry<K, V>> entrySet ()

Since: API Level 1

Returns a set of the mappings contained in this Hashtable. Each element in the set is a Map.Entry. The set is backed by this Hashtable so changes to one are reflected by the other. The set does not support adding.

Returns
  • a set of the mappings.

public synchronized boolean equals (Object object)

Since: API Level 1

Compares this Hashtable with the specified object and indicates if they are equal. In order to be equal, object must be an instance of Map and contain the same key/value pairs.

Parameters
object the object to compare with this object.
Returns
  • true if the specified object is equal to this Map, false otherwise.
See Also

public synchronized V get (Object key)

Since: API Level 1

Returns the value associated with the specified key in this Hashtable.

Parameters
key the key of the value returned.
Returns
  • the value associated with the specified key, or null if the specified key does not exist.
See Also

public synchronized int hashCode ()

Since: API Level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Returns
  • this object's hash code.

public synchronized boolean isEmpty ()

Since: API Level 1

Returns true if this Hashtable has no key/value pairs.

Returns
  • true if this Hashtable has no key/value pairs, false otherwise.
See Also

public synchronized Set<K> keySet ()

Since: API Level 1

Returns a set of the keys contained in this Hashtable. The set is backed by this Hashtable so changes to one are reflected by the other. The set does not support adding.

Returns
  • a set of the keys.

public synchronized Enumeration<K> keys ()

Since: API Level 1

Returns an enumeration on the keys of this Hashtable instance. The results of the enumeration may be affected if the contents of this Hashtable are modified.

Returns
  • an enumeration of the keys of this Hashtable.

public synchronized V put (K key, V value)

Since: API Level 1

Associate the specified value with the specified key in this Hashtable. If the key already exists, the old value is replaced. The key and value cannot be null.

Parameters
key the key to add.
value the value to add.
Returns
  • the old value associated with the specified key, or null if the key did not exist.

public synchronized void putAll (Map<? extends K, ? extends V> map)

Since: API Level 1

Copies every mapping to this Hashtable from the specified map.

Parameters
map the map to copy mappings from.

public synchronized V remove (Object key)

Since: API Level 1

Removes the key/value pair with the specified key from this Hashtable.

Parameters
key the key to remove.
Returns
  • the value associated with the specified key, or null if the specified key did not exist.

public synchronized int size ()

Since: API Level 1

Returns the number of key/value pairs in this Hashtable.

Returns
  • the number of key/value pairs in this Hashtable.
See Also

public synchronized String toString ()

Since: API Level 1

Returns the string representation of this Hashtable.

Returns
  • the string representation of this Hashtable.

public synchronized Collection<V> values ()

Since: API Level 1

Returns a collection of the values contained in this Hashtable. The collection is backed by this Hashtable so changes to one are reflected by the other. The collection does not support adding.

Returns
  • a collection of the values.

Protected Methods

protected void rehash ()

Since: API Level 1

Increases the capacity of this Hashtable. This method is called when the size of this Hashtable exceeds the load factor.