Class Hashtable<K,V>
- All Implemented Interfaces:
Map<K,V>
Hashtable associates keys with values. Both keys and values cannot be null. The size of the Hashtable is the number of key/value pairs it contains. The capacity is the number of key/value pairs the Hashtable can hold. The load factor is a float value which determines how full the Hashtable gets before expanding the capacity. If the load factor of the Hashtable is exceeded, the capacity is doubled.
See also
-
Enumeration
-
java.io.Serializable
-
java.lang.Object#equals
-
java.lang.Object#hashCode
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newHashtableusing the default capacity and load factor.Hashtable(int capacity) Constructs a newHashtableusing the specified capacity and the default load factor.Hashtable(int capacity, float loadFactor) Constructs a newHashtableusing the specified capacity and load factor.Constructs a new instance ofHashtablecontaining the mappings from the specified map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all key/value pairs from thisHashtable, leaving the size zero and the capacity unchanged.booleanReturns true if thisHashtablecontains the specified object as the value of at least one of the key/value pairs.booleancontainsKey(Object key) Returns true if thisHashtablecontains the specified object as a key of one of the key/value pairs.booleancontainsValue(Object value) Searches thisHashtablefor the specified value.elements()Returns an enumeration on the values of thisHashtable.entrySet()Returns a set of the mappings contained in thisHashtable.booleanCompares thisHashtablewith the specified object and indicates if they are equal.Returns the value associated with the specified key in thisHashtable.inthashCode()Returns an integer hash code for the receiver.booleanisEmpty()Returns true if thisHashtablehas no key/value pairs.keys()Returns an enumeration on the keys of thisHashtableinstance.keySet()Returns a set of the keys contained in thisHashtable.Associate the specified value with the specified key in thisHashtable.voidCopies every mapping to thisHashtablefrom the specified map.protected voidrehash()Increases the capacity of thisHashtable.Removes the key/value pair with the specified key from thisHashtable.intsize()Returns the number of key/value pairs in thisHashtable.toString()Returns the string representation of thisHashtable.values()Returns a collection of the values contained in thisHashtable.
-
Constructor Details
-
Hashtable
public Hashtable()Constructs a newHashtableusing the default capacity and load factor. -
Hashtable
public Hashtable(int capacity) Constructs a new
Hashtableusing the specified capacity and the default load factor.Parameters
capacity: the initial capacity.
-
Hashtable
public Hashtable(int capacity, float loadFactor) Constructs a new
Hashtableusing the specified capacity and load factor.Parameters
-
capacity: the initial capacity. -
loadFactor: the initial load factor.
-
-
Hashtable
-
-
Method Details
-
clear
-
contains
Returns true if this
Hashtablecontains the specified object as the value of at least one of the key/value pairs.Parameters
value: the object to look for as a value in thisHashtable.
Returns
- Returns:
trueif object is a value in thisHashtable,falseotherwise.See also
-
#containsKey
-
java.lang.Object#equals
-
-
containsKey
Returns true if this
Hashtablecontains the specified object as a key of one of the key/value pairs.Parameters
key: the object to look for as a key in thisHashtable.
Returns
- Specified by:
containsKeyin interfaceMap<K,V> - Returns:
trueif object is a key in thisHashtable,falseotherwise.See also
-
#contains
-
java.lang.Object#equals
-
-
containsValue
Searches this
Hashtablefor the specified value.Parameters
value: the object to search for.
Returns
- Specified by:
containsValuein interfaceMap<K,V> - Returns:
trueifvalueis a value of thisHashtable,falseotherwise.
-
elements
Returns an enumeration on the values of this
Hashtable. The results of the Enumeration may be affected if the contents of thisHashtableare modified.Returns
an enumeration of the values of this
Hashtable.See also
-
#keys
-
#size
-
Enumeration
- Specified by:
elementsin classDictionary<K,V>
-
-
entrySet
Returns a set of the mappings contained in this
Hashtable. Each element in the set is aMap.Entry. The set is backed by thisHashtableso changes to one are reflected by the other. The set does not support adding.Returns
a set of the mappings.
-
equals
Compares this
Hashtablewith the specified object and indicates if they are equal. In order to be equal,objectmust be an instance of Map and contain the same key/value pairs.Parameters
object: the object to compare with this object.
Returns
-
get
Returns the value associated with the specified key in this
Hashtable.Parameters
key: the key of the value returned.
Returns
-
hashCode
public int hashCode()Description copied from interface:MapReturns an integer hash code for the receiver.
Objects which are equal return the same value for this method.Returns
the receiver's hash.
See also
- #equals(Object)
-
isEmpty
-
keys
Returns an enumeration on the keys of this
Hashtableinstance. The results of the enumeration may be affected if the contents of thisHashtableare modified.Returns
an enumeration of the keys of this
Hashtable.See also
-
#elements
-
#size
-
Enumeration
- Specified by:
keysin classDictionary<K,V>
-
-
keySet
-
put
Associate the specified value with the specified key in this
Hashtable. If the key already exists, the old value is replaced. The key and value cannot be null.Parameters
-
key: the key to add. -
value: the value to add.
Returns
-
-
putAll
-
rehash
protected void rehash()Increases the capacity of thisHashtable. This method is called when the size of thisHashtableexceeds the load factor. -
remove
Removes the key/value pair with the specified key from this
Hashtable.Parameters
key: the key to remove.
Returns
-
size
-
toString
-
values
Returns a collection of the values contained in this
Hashtable. The collection is backed by thisHashtableso changes to one are reflected by the other. The collection does not support adding.Returns
a collection of the values.
-