# Class Hashtable<K,V>

java.lang.Object
java.util.Dictionary<K,V>
java.util.Hashtable<K,V>

All Implemented Interfaces:
  `Map<K,V>`

public class Hashtable<K,V> extends Dictionary<K,V> implements Map<K,V>
Hashtable associates keys with values. Both keys and values cannot be null. The size of the Hashtable is the number of key/value pairs it contains. The capacity is the number of key/value pairs the Hashtable can hold. The load factor is a float value which determines how full the Hashtable gets before expanding the capacity. If the load factor of the Hashtable is exceeded, the capacity is doubled.

See Also:
  - `Enumeration`
  - `Serializable`
  - `Object.equals(Object)`
  - `Object.hashCode()`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `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.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Removes all key/value pairs from this `Hashtable`, leaving the size zero and the capacity unchanged.
  `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.
  `boolean`
  `containsKey(Object key)`
  Returns true if this `Hashtable` contains the specified object as a key of one of the key/value pairs.
  `boolean`
  `containsValue(Object value)`
  Searches this `Hashtable` for the specified value.
  `Enumeration<V>`
  `elements()`
  Returns an enumeration on the values of this `Hashtable`.
  `Set<Map.Entry<K,V>>`
  `entrySet()`
  Returns a set of the mappings contained in this `Hashtable`.
  `boolean`
  `equals(Object object)`
  Compares this `Hashtable` with the specified object and indicates if they are equal.
  `V`
  `get(Object key)`
  Returns the value associated with the specified key in this `Hashtable`.
  `int`
  `hashCode()`
  Returns an integer hash code for the receiver.
  `boolean`
  `isEmpty()`
  Returns true if this `Hashtable` has no key/value pairs.
  `Enumeration<K>`
  `keys()`
  Returns an enumeration on the keys of this `Hashtable` instance.
  `Set<K>`
  `keySet()`
  Returns a set of the keys contained in this `Hashtable`.
  `V`
  `put(K key, V value)`
  Associate the specified value with the specified key in this `Hashtable`.
  `void`
  `putAll(Map<? extends K, ? extends V> map)`
  Copies every mapping to this `Hashtable` from the specified map.
  `protected void`
  `rehash()`
  Increases the capacity of this `Hashtable`.
  `V`
  `remove(Object key)`
  Removes the key/value pair with the specified key from this `Hashtable`.
  `int`
  `size()`
  Returns the number of key/value pairs in this `Hashtable`.
  `String`
  `toString()`
  Returns the string representation of this `Hashtable`.
  `Collection<V>`
  `values()`
  Returns a collection of the values contained in this `Hashtable`.

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  `final Class`
  `getClass()`
  Returns the runtime class of an object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes current thread to wait until another thread invokes the method or the method for this object.
  `final void`
  `wait(long timeout)`
  Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.
  `final void`
  `wait(long timeout, int nanos)`
  Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

- ## Constructor Details

  - ### Hashtable

    public Hashtable()
    Constructs a new `Hashtable` using the default capacity and load factor.

  - ### Hashtable

    public Hashtable(int capacity)
    Constructs a new `Hashtable` using the specified capacity and the default load factor.
    Parameters:
      `capacity` - the initial capacity.

  - ### Hashtable

    public Hashtable(int capacity, float loadFactor)
    Constructs a new `Hashtable` using the specified capacity and load factor.
    Parameters:
      `capacity` - the initial capacity.
      `loadFactor` - the initial load factor.

  - ### Hashtable

    public Hashtable(Map<? extends K, ? extends V> map)
    Constructs a new instance of `Hashtable` containing the mappings from the specified map.
    Parameters:
      `map` - the mappings to add.

- ## Method Details

  - ### clear

    public void clear()
    Removes all key/value pairs from this `Hashtable`, leaving the size zero and the capacity unchanged.
    Specified by:
      `clear` in interface `Map<K,V>`
    See Also:
      - `isEmpty()`
      - `size()`

  - ### contains

    public 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.
    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.
    See Also:
      - `containsKey(Object)`
      - `Object.equals(Object)`

  - ### containsKey

    public boolean containsKey(Object key)
    Returns true if this `Hashtable` contains the specified object as a key of one of the key/value pairs.
    Specified by:
      `containsKey` in interface `Map<K,V>`
    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.
    See Also:
      - `contains(Object)`
      - `Object.equals(Object)`

  - ### containsValue

    public boolean containsValue(Object value)
    Searches this `Hashtable` for the specified value.
    Specified by:
      `containsValue` in interface `Map<K,V>`
    Parameters:
      `value` - the object to search for.
    Returns:
      `true` if `value` is a value of this `Hashtable`, `false` otherwise.

  - ### elements

    public Enumeration<V> elements()
    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.
    Specified by:
      `elements` in class `Dictionary<K,V>`
    Returns:
      an enumeration of the values of this `Hashtable`.
    See Also:
      - `keys()`
      - `size()`
      - `Enumeration`

  - ### entrySet

    public Set<Map.Entry<K,V>> entrySet()
    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.
    Specified by:
      `entrySet` in interface `Map<K,V>`
    Returns:
      a set of the mappings.

  - ### equals

    public boolean equals(Object object)
    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.
    Specified by:
      `equals` in interface `Map<K,V>`
    Overrides:
      `equals` in class `Object`
    Parameters:
      `object` - the object to compare with this object.
    Returns:
      `true` if the specified object is equal to this Map, `false` otherwise.
    See Also:
      - `hashCode()`

  - ### get

    public V get(Object key)
    Returns the value associated with the specified key in this `Hashtable`.
    Specified by:
      `get` in interface `Map<K,V>`
    Specified by:
      `get` in class `Dictionary<K,V>`
    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:
      - `put(K, V)`

  - ### hashCode

    public int hashCode()
    Description copied from interface: `Map`
    Returns an integer hash code for the receiver. `Object`s which are equal return the same value for this method.
    Specified by:
      `hashCode` in interface `Map<K,V>`
    Overrides:
      `hashCode` in class `Object`
    Returns:
      the receiver's hash.
    See Also:
      - `Map.equals(Object)`

  - ### isEmpty

    public boolean isEmpty()
    Returns true if this `Hashtable` has no key/value pairs.
    Specified by:
      `isEmpty` in interface `Map<K,V>`
    Specified by:
      `isEmpty` in class `Dictionary<K,V>`
    Returns:
      `true` if this `Hashtable` has no key/value pairs, `false` otherwise.
    See Also:
      - `size()`

  - ### keys

    public Enumeration<K> keys()
    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.
    Specified by:
      `keys` in class `Dictionary<K,V>`
    Returns:
      an enumeration of the keys of this `Hashtable`.
    See Also:
      - `elements()`
      - `size()`
      - `Enumeration`

  - ### keySet

    public Set<K> keySet()
    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.
    Specified by:
      `keySet` in interface `Map<K,V>`
    Returns:
      a set of the keys.

  - ### put

    public V put(K key, V value)
    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.
    Specified by:
      `put` in interface `Map<K,V>`
    Specified by:
      `put` in class `Dictionary<K,V>`
    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.
    See Also:
      - `elements()`
      - `get(Object)`
      - `keys()`
      - `Object.equals(Object)`

  - ### putAll

    public void putAll(Map<? extends K, ? extends V> map)
    Copies every mapping to this `Hashtable` from the specified map.
    Specified by:
      `putAll` in interface `Map<K,V>`
    Parameters:
      `map` - the map to copy mappings from.

  - ### rehash

    protected void rehash()
    Increases the capacity of this `Hashtable`. This method is called when the size of this `Hashtable` exceeds the load factor.

  - ### remove

    public V remove(Object key)
    Removes the key/value pair with the specified key from this `Hashtable`.
    Specified by:
      `remove` in interface `Map<K,V>`
    Specified by:
      `remove` in class `Dictionary<K,V>`
    Parameters:
      `key` - the key to remove.
    Returns:
      the value associated with the specified key, or `null` if the specified key did not exist.
    See Also:
      - `get(Object)`
      - `put(K, V)`

  - ### size

    public int size()
    Returns the number of key/value pairs in this `Hashtable`.
    Specified by:
      `size` in interface `Map<K,V>`
    Specified by:
      `size` in class `Dictionary<K,V>`
    Returns:
      the number of key/value pairs in this `Hashtable`.
    See Also:
      - `elements()`
      - `keys()`

  - ### toString

    public String toString()
    Returns the string representation of this `Hashtable`.
    Overrides:
      `toString` in class `Object`
    Returns:
      the string representation of this `Hashtable`.

  - ### values

    public Collection<V> values()
    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.
    Specified by:
      `values` in interface `Map<K,V>`
    Returns:
      a collection of the values.