Class Hashtable<K,V>
java.lang.Object
java.util.Dictionary<K,V>
java.util.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:
-
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 newHashtableusing the specified capacity and the default load factor.- Parameters:
capacity- the initial capacity.
-
Hashtable
public Hashtable(int capacity, float loadFactor) Constructs a newHashtableusing the specified capacity and load factor.- Parameters:
capacity- the initial capacity.loadFactor- the initial load factor.
-
Hashtable
-
-
Method Details
-
clear
-
contains
Returns true if thisHashtablecontains 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:
trueif object is a value in thisHashtable,falseotherwise.- See Also:
-
containsKey
Returns true if thisHashtablecontains the specified object as a key of one of the key/value pairs.- Specified by:
containsKeyin interfaceMap<K,V> - Parameters:
key- the object to look for as a key in thisHashtable.- Returns:
trueif object is a key in thisHashtable,falseotherwise.- See Also:
-
containsValue
Searches thisHashtablefor the specified value.- Specified by:
containsValuein interfaceMap<K,V> - Parameters:
value- the object to search for.- Returns:
trueifvalueis a value of thisHashtable,falseotherwise.
-
elements
Returns an enumeration on the values of thisHashtable. The results of the Enumeration may be affected if the contents of thisHashtableare modified.- Specified by:
elementsin classDictionary<K,V> - Returns:
- an enumeration of the values of this
Hashtable. - See Also:
-
entrySet
Returns a set of the mappings contained in thisHashtable. 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. -
equals
Compares thisHashtablewith 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. -
get
Returns the value associated with the specified key in thisHashtable. -
hashCode
-
isEmpty
-
keys
Returns an enumeration on the keys of thisHashtableinstance. The results of the enumeration may be affected if the contents of thisHashtableare modified.- Specified by:
keysin classDictionary<K,V> - Returns:
- an enumeration of the keys of this
Hashtable. - See Also:
-
keySet
-
put
Associate the specified value with the specified key in thisHashtable. If the key already exists, the old value is replaced. The key and value cannot be null. -
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 thisHashtable. -
size
-
toString
-
values
Returns a collection of the values contained in thisHashtable. The collection is backed by thisHashtableso changes to one are reflected by the other. The collection does not support adding.
-