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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears this hashtable so that it contains no keysboolean
Tests if some key maps into the specified value in this hashtable.boolean
containsKey
(Object key) Tests if the specified object is a key in this hashtable.elements()
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.Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.int
hashCode()
Returns the hash code value for this Map as per the definition in the Map interface.boolean
isEmpty()
Tests if this hashtable maps no keys to values.keys()
Returns an enumeration of the keys in this hashtable.Maps the specifiedkey
to the specifiedvalue
in this hashtable.Removes the key (and its corresponding value) from this hashtable.int
size()
Returns the number of keys in this hashtable.toString()
Returns a string representation of thisHashtable
object 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 thecontainsKey
method.Note that this method is identical in functionality to
invalid @link
containsValue
HMap
interface in the collections framework).- Parameters:
value
- a value to search for- Returns:
true
if and only if some key maps to thevalue
argument in this hashtable as determined by theequals
method;false
otherwise.- Throws:
NullPointerException
- if the value isnull
-
containsKey
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 theequals
method;false
otherwise.- 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, ornull
if this map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a valuev
such 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
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
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 specifiedkey
to the specifiedvalue
in this hashtable. Neither the key nor the value can benull
.The value can be retrieved by calling the
get
method 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
null
if 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
null
if 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 thisHashtable
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 thetoString
method 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.
-