Package myAdapter

Class Hashtable

java.lang.Object
myAdapter.Hashtable

public class Hashtable extends Object
The Hashtable class behaves like the Hashtable class from the version of Java Micro Edition CLDC 1.1. The last one has fewer methods than the standard Java's one.

Note that in Hashtable class of CLDC 1.1 null keys or values are forbidden.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).
    Hashtable(int initialCapacity)
    Constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears this hashtable so that it contains no keys
    boolean
    Tests if some key maps into the specified value in this hashtable.
    boolean
    Tests if the specified object is a key in this hashtable.
    Returns an enumeration of the values in this hashtable.
    boolean
    Compares the specified Object with this Map for equality, as per the definition in the HMap interface.
    get(Object key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    int
    Returns the hash code value for this Map as per the definition in the Map interface.
    boolean
    Tests if this hashtable maps no keys to values.
    Returns an enumeration of the keys in this hashtable.
    put(Object key, Object value)
    Maps the specified key to the specified value in this hashtable.
    Removes the key (and its corresponding value) from this hashtable.
    int
    Returns the number of keys in this hashtable.
    Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Hashtable

      public Hashtable()
      Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).
    • Hashtable

      public Hashtable(int initialCapacity)
      Constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75).
      Parameters:
      initialCapacity - the initial capacity of the hashtable.
      Throws:
      IllegalArgumentException - if the initial capacity is less than zero.
  • Method Details

    • clear

      public void clear()
      Clears this hashtable so that it contains no keys
    • contains

      public boolean contains(Object value)
      Tests if some key maps into the specified value in this hashtable. This operation is more expensive than the containsKey method.

      Note that this method is identical in functionality to

      invalid @link
      containsValue
      , (which is part of the HMap interface in the collections framework).
      Parameters:
      value - a value to search for
      Returns:
      true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.
      Throws:
      NullPointerException - if the value is null
    • containsKey

      public boolean containsKey(Object key)
      Tests if the specified object is a key in this hashtable.
      Parameters:
      key - possible key
      Returns:
      true if and only if the specified object is a key in this hashtable, as determined by the equals method; false otherwise.
      Throws:
      NullPointerException - if the key is null
      See Also:
    • elements

      public Enumeration elements()
      Returns an enumeration of the values in this hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially. If the hashtable is structurally modified while enumerating over the values then the results of enumerating are undefined.
      Returns:
      an enumeration of the values in this hashtable.
      See Also:
    • get

      public Object get(Object key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

      More formally, if this map contains a mapping from a key k to a value v such that (key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value to which the specified key is mapped, or null if this map contains no mapping for the key
      Throws:
      NullPointerException - if the specified key is null
      See Also:
    • isEmpty

      public boolean isEmpty()
      Tests if this hashtable maps no keys to values.
      Returns:
      true if this hashtable maps no keys to values; false otherwise.
    • keys

      public Enumeration keys()
      Returns an enumeration of the keys in this hashtable. Use the Enumeration methods on the returned object to fetch the keys sequentially. If the hashtable is structurally modified while enumerating over the keys then the results of enumerating are undefined.
      Returns:
      an enumeration of the keys in this hashtable.
      See Also:
    • put

      public Object put(Object key, Object value)
      Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.

      The value can be retrieved by calling the get method with a key that is equal to the original key.

      Parameters:
      key - the hashtable key
      value - the value
      Returns:
      the previous value of the specified key in this hashtable, or null if it did not have one
      Throws:
      NullPointerException - if the key or value is null
      See Also:
    • remove

      public Object remove(Object key)
      Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.
      Parameters:
      key - the key that needs to be removed
      Returns:
      the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping
      Throws:
      NullPointerException - if the key is null
    • size

      public int size()
      Returns the number of keys in this hashtable.
      Returns:
      the number of keys in this hashtable.
    • toString

      public String toString()
      Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space). Each entry is rendered as the key, an equals sign =, and the associated element, where the toString method is used to convert the key and element to strings.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this hashtable
    • equals

      public boolean equals(Object o)
      Compares the specified Object with this Map for equality, as per the definition in the HMap interface.
      Overrides:
      equals in class Object
      Parameters:
      o - object to be compared for equality with this hashtable
      Returns:
      true if the specified Object is equal to this Map
    • hashCode

      public int hashCode()
      Returns the hash code value for this Map as per the definition in the Map interface.
      Overrides:
      hashCode in class Object
      See Also:
      • invalid @see
        Map#hashCode()