Package myAdapter
Class Hashtable
java.lang.Object
myAdapter.Hashtable
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears this hashtable so that it contains no keysbooleanTests if some key maps into the specified value in this hashtable.booleancontainsKey(Object key) Tests if the specified object is a key in this hashtable.elements()Returns an enumeration of the values in this hashtable.booleanCompares the specified Object with this Map for equality, as per the definition in the HMap interface.Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.inthashCode()Returns the hash code value for this Map as per the definition in the Map interface.booleanisEmpty()Tests if this hashtable maps no keys to values.keys()Returns an enumeration of the keys in this hashtable.Maps the specifiedkeyto the specifiedvaluein this hashtable.Removes the key (and its corresponding value) from this hashtable.intsize()Returns the number of keys in this hashtable.toString()Returns a string representation of thisHashtableobject in the form of a set of entries, enclosed in braces and separated by the ASCII characters "," (comma and space).
-
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
Tests if some key maps into the specified value in this hashtable. This operation is more expensive than thecontainsKeymethod.Note that this method is identical in functionality to
, (which is part of theinvalid @link
containsValueHMapinterface in the collections framework).- Parameters:
value- a value to search for- Returns:
trueif and only if some key maps to thevalueargument in this hashtable as determined by theequalsmethod;falseotherwise.- Throws:
NullPointerException- if the value isnull
-
containsKey
Tests if the specified object is a key in this hashtable.- Parameters:
key- possible key- Returns:
trueif and only if the specified object is a key in this hashtable, as determined by theequalsmethod;falseotherwise.- Throws:
NullPointerException- if the key isnull- See Also:
-
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
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch that(key.equals(k)), then this method returnsv; otherwise it returnsnull. (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
nullif 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:
trueif this hashtable maps no keys to values;falseotherwise.
-
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
Maps the specifiedkeyto the specifiedvaluein this hashtable. Neither the key nor the value can benull.The value can be retrieved by calling the
getmethod with a key that is equal to the original key.- Parameters:
key- the hashtable keyvalue- the value- Returns:
- the previous value of the specified key in this hashtable,
or
nullif it did not have one - Throws:
NullPointerException- if the key or value isnull- See Also:
-
remove
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
nullif the key did not have a mapping - Throws:
NullPointerException- if the key isnull
-
size
public int size()Returns the number of keys in this hashtable.- Returns:
- the number of keys in this hashtable.
-
toString
Returns a string representation of thisHashtableobject 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 thetoStringmethod is used to convert the key and element to strings. -
equals
Compares the specified Object with this Map for equality, as per the definition in the HMap interface. -
hashCode
public int hashCode()Returns the hash code value for this Map as per the definition in the Map interface.
-