K - the type of keys maintained by this mapV - the type of mapped valuespublic class Hashtable<K,V> extends Dictionary<K,V> implements Map<K,V>, Cloneable, Serializable
Map. All optional operations are supported.
Neither keys nor values can be null. (Use HashMap or LinkedHashMap if you
need null keys or values.)
HashMap,
Serialized Form| 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. |
Hashtable(int capacity,
float loadFactor)
Constructs a new
Hashtable using the specified capacity and load
factor. |
Hashtable(Map<? extends K,? extends V> map)
Constructs a new instance of
Hashtable containing the mappings
from the specified map. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all key/value pairs from this
Hashtable, leaving the
size zero and the capacity unchanged. |
Object |
clone()
Returns a new
Hashtable with the same key/value pairs, capacity
and load factor. |
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. |
boolean |
containsValue(Object value)
Searches this
Hashtable for the specified value. |
Enumeration<V> |
elements()
Returns an enumeration on the values of this
Hashtable. |
Set<Map.Entry<K,V>> |
entrySet()
Returns a set of the mappings contained in 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 an integer hash code for this object.
|
boolean |
isEmpty()
Returns true if this
Hashtable has no key/value pairs. |
Enumeration<K> |
keys()
Returns an enumeration on the keys of this
Hashtable instance. |
Set<K> |
keySet()
Returns a set of the keys contained in this
Hashtable. |
V |
put(K key,
V value)
Associate the specified value with the specified key in this
Hashtable. |
void |
putAll(Map<? extends K,? extends V> map)
Copies every mapping to this
Hashtable from the specified map. |
protected void |
rehash()
Increases the capacity of 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. |
Collection<V> |
values()
Returns a collection of the values contained in this
Hashtable. |
public Hashtable()
Hashtable using the default capacity and load
factor.public Hashtable(int capacity)
Hashtable using the specified capacity and the
default load factor.capacity - the initial capacity.public Hashtable(int capacity,
float loadFactor)
Hashtable using the specified capacity and load
factor.capacity - the initial capacity.loadFactor - the initial load factor.public Object clone()
Hashtable with the same key/value pairs, capacity
and load factor.public boolean isEmpty()
Hashtable has no key/value pairs.public int size()
Hashtable.size in interface Map<K,V>size in class Dictionary<K,V>Hashtable.elements(),
keys()public boolean containsKey(Object key)
Hashtable contains the specified object as a
key of one of the key/value pairs.containsKey in interface Map<K,V>key - the object to look for as a key in this Hashtable.true if object is a key in this Hashtable,
false otherwise.contains(java.lang.Object),
Object.equals(java.lang.Object)public boolean containsValue(Object value)
Hashtable for the specified value.containsValue in interface Map<K,V>value - the object to search for.true if value is a value of this
Hashtable, false otherwise.public boolean contains(Object value)
Hashtable contains the specified object as
the value of at least one of the key/value pairs.value - the object to look for as a value in this Hashtable.true if object is a value in this Hashtable,
false otherwise.containsKey(java.lang.Object),
Object.equals(java.lang.Object)public V put(K key, V value)
Hashtable. If the key already exists, the old value is replaced.
The key and value cannot be null.put in interface Map<K,V>put in class Dictionary<K,V>key - the key to add.value - the value to add.null
if the key did not exist.elements(),
get(java.lang.Object),
keys(),
Object.equals(java.lang.Object)public void putAll(Map<? extends K,? extends V> map)
Hashtable from the specified map.protected void rehash()
Hashtable. This method is called
when the size of this Hashtable exceeds the load factor.public V remove(Object key)
Hashtable.remove in interface Map<K,V>remove in class Dictionary<K,V>key - the key to remove.null if
the specified key did not exist.get(java.lang.Object),
put(K, V)public void clear()
Hashtable, leaving the
size zero and the capacity unchanged.public Set<K> keySet()
Hashtable. The set
is backed by this Hashtable so changes to one are reflected by
the other. The set does not support adding.public Collection<V> values()
Hashtable.
The collection is backed by this Hashtable so changes to one are
reflected by the other. The collection does not support adding.public Set<Map.Entry<K,V>> entrySet()
Hashtable. Each
element in the set is a Map.Entry. The set is backed by this
Hashtable so changes to one are reflected by the other. The set
does not support adding.public Enumeration<K> keys()
Hashtable instance.
The results of the enumeration may be affected if the contents of this
Hashtable are modified.keys in class Dictionary<K,V>Hashtable.elements(),
size,
Enumerationpublic Enumeration<V> elements()
Hashtable. The
results of the Enumeration may be affected if the contents of this
Hashtable are modified.elements in class Dictionary<K,V>Hashtable.keys(),
size,
Enumerationpublic boolean equals(Object object)
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.public int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.