K - Type used for KeysV - Type used for Valuespublic class Hashtable<K,V> extends Dictionary<K,V> implements Cloneable
| Constructor and Description |
|---|
Hashtable()
Constructs a new, empty hashtable with a default initial capacity (11)
and load factor (0.75).
|
Hashtable(int initcap)
Constructs a new, empty hashtable with the specified initial capacity
and default load factor (0.75).
|
Hashtable(int initcap,
float loadfact)
Constructs a new, empty hashtable with the specified initial
capacity and the specified load factor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears this hashtable so that it contains no keys.
|
Hashtable<K,V> |
clone()
Creates a new object of the same class as this object.
|
boolean |
contains(Object value)
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.
|
Enumeration<V> |
elements()
Returns an enumeration of the values in this hashtable.
|
V |
get(K key)
Returns the value to which the specified key is mapped,
or
null if this map contains no mapping for the key. |
boolean |
isEmpty()
Tests if this hashtable maps no keys to values.
|
Enumeration<K> |
keys()
Returns an enumeration of the keys in this hashtable.
|
V |
put(K key,
V value)
Maps the specified
key to the specified
value in this hashtable. |
protected void |
rehash()
Increases the capacity of and internally reorganizes this
hashtable, in order to accommodate and access its entries more
efficiently.
|
V |
remove(K key)
Removes the key (and its corresponding value) from this
hashtable.
|
int |
size()
Returns the number of keys in this hashtable.
|
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).
|
public Hashtable()
public Hashtable(int initcap)
initcap - the initial capacity of the hashtable.public Hashtable(int initcap,
float loadfact)
initcap - the initial capacity of the hashtable.loadfact - the load factor of the hashtable.IllegalArgumentException - if the initial capacity is less
than zero, or if the load factor is nonpositive.public void clear()
public Hashtable<K,V> clone()
Object
The clone method of class Object will
only clone an object whose class indicates that it is willing for
its instances to be cloned. A class indicates that its instances
can be cloned by declaring that it implements the
Cloneable interface.
public boolean contains(Object value)
value - a value to search fortrue if and only if some key maps to the
value argument in this hashtable as
determined by the equals method;
false otherwise.NullPointerException - if the value is nullpublic boolean containsKey(Object key)
key - possible keytrue if and only if the specified object
is a key in this hashtable, as determined by the
equals method; false otherwise.public Enumeration<V> elements()
elements in class Dictionary<K,V>public V get(K key)
null if this map contains no mapping for the key.get in class Dictionary<K,V>key - the key whose associated value is to be returnednull if this map contains no mapping for the keyNullPointerException - if the specified key is nullput(Object, Object)public boolean isEmpty()
isEmpty in class Dictionary<K,V>true if this hashtable maps no keys to values;
false otherwise.public Enumeration<K> keys()
keys in class Dictionary<K,V>public V put(K key, V value)
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.
put in class Dictionary<K,V>key - the hashtable keyvalue - the valuenull if it did not have oneNullPointerException - if the key or value is
nullprotected void rehash()
public V remove(K key)
remove in class Dictionary<K,V>key - the key that needs to be removednull if the key did not have a mappingNullPointerException - if the key is nullpublic int size()
size in class Dictionary<K,V>public String toString()