Intel

Developer Zone

Hashtable

java.util

Class Hashtable<K,V>



  • public class Hashtable<K,V>
    extends Object
    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, Object.equals(java.lang.Object), Object.hashCode()
    • Constructor Summary

      Constructors
      Constructor and 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.
    • Method Summary

      Methods
      Modifier and Type Method and 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.
      Enumeration<V> elements()
      Returns an enumeration on the values of 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 the hash code for this Hashtable.
      boolean isEmpty()
      Returns whether this Hashtable contains no elements.
      Enumeration<K> keys()
      Returns an enumeration on the keys of this Hashtable instance.
      V put(K key, V value)
      Associate the specified value with the specified key in 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.
    • Constructor Detail

      • 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.
    • Method Detail

      • clear

        public void clear()
        Removes all key/value pairs from this Hashtable, leaving the size zero and the capacity unchanged.
        See Also:
        isEmpty(), size()
      • isEmpty

        public boolean isEmpty()
        Returns whether this Hashtable contains no elements.
        Returns:
        true if this Hashtable has no elements, false otherwise.
      • 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.
        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(java.lang.Object), Object.equals(java.lang.Object)
      • get

        public V get(Object key)
        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:
        put(K, V)
      • 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.
        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(java.lang.Object), keys(), Object.equals(java.lang.Object)
      • remove

        public V remove(Object key)
        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.
        See Also:
        get(java.lang.Object), put(K, V)
      • size

        public int size()
        Returns the number of key/value pairs in this Hashtable.
        Returns:
        the number of key/value pairs in this Hashtable.
        See Also:
        elements(), keys()
      • 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(java.lang.Object), Object.equals(java.lang.Object)
      • 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.
        Returns:
        an enumeration of the values of this Hashtable.
        See Also:
        keys(), size(), Enumeration
      • 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.
        Returns:
        an enumeration of the keys of this Hashtable.
        See Also:
        elements(), size(), Enumeration
      • 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.
        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()
      • hashCode

        public int hashCode()
        Returns the hash code for this Hashtable. It is calculated by taking each element' hashcode.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code of the Hashtable.
        See Also:
        Object.equals(java.lang.Object)
      • toString

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