Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Hashtable

public class Hashtable
extends Dictionary<K, V> implements Map<K, V>, Cloneable, Serializable

java.lang.Object
   ↳ java.util.Dictionary<K, V>
     ↳ java.util.Hashtable<K, V>
Known Direct Subclasses
Known Indirect Subclasses


Hashtable is a synchronized implementation of Map. All optional operations are supported.

Neither keys nor values can be null. (Use HashMap or LinkedHashMap if you need null keys or values.)

See also:

Summary

Public constructors

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.

Public methods

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<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.

Set<K> keySet()

Returns a set of the keys contained in this Hashtable.

Enumeration<K> keys()

Returns an enumeration on the keys of this Hashtable instance.

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.

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.

Protected methods

void rehash()

Increases the capacity of this Hashtable.

Inherited methods

From class java.util.Dictionary
From class java.lang.Object
From interface java.util.Map

Public constructors

Hashtable

Added in API level 1
Hashtable ()

Constructs a new Hashtable using the default capacity and load factor.

Hashtable

Added in API level 1
Hashtable (int capacity)

Constructs a new Hashtable using the specified capacity and the default load factor.

Parameters
capacity int: the initial capacity.

Hashtable

Added in API level 1
Hashtable (int capacity, 
                float loadFactor)

Constructs a new Hashtable using the specified capacity and load factor.

Parameters
capacity int: the initial capacity.
loadFactor float: the initial load factor.

Hashtable

Added in API level 1
Hashtable (Map<? extends K, ? extends V> map)

Constructs a new instance of Hashtable containing the mappings from the specified map.

Parameters
map Map: the mappings to add.

Public methods

clear

Added in API level 1
void clear ()

Removes all key/value pairs from this Hashtable, leaving the size zero and the capacity unchanged.

See also:

clone

Added in API level 1
Object clone ()

Returns a new Hashtable with the same key/value pairs, capacity and load factor.

Returns
Object a shallow copy of this Hashtable.

See also:

contains

Added in API level 1
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.

Parameters
value Object: the object to look for as a value in this Hashtable.
Returns
boolean true if object is a value in this Hashtable, false otherwise.

See also:

containsKey

Added in API level 1
boolean containsKey (Object key)

Returns true if this Hashtable contains the specified object as a key of one of the key/value pairs.

Parameters
key Object: the object to look for as a key in this Hashtable.
Returns
boolean true if object is a key in this Hashtable, false otherwise.

See also:

containsValue

Added in API level 1
boolean containsValue (Object value)

Searches this Hashtable for the specified value.

Parameters
value Object: the object to search for.
Returns
boolean true if value is a value of this Hashtable, false otherwise.

elements

Added in API level 1
Enumeration<V> elements ()

Returns an enumeration on the values of this Hashtable. The results of the Enumeration may be affected if the contents of this Hashtable are modified.

Returns
Enumeration<V> an enumeration of the values of this Hashtable.

See also:

entrySet

Added in API level 1
Set<Entry<K, V>> entrySet ()

Returns a set of the mappings contained in this 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.

Returns
Set<Entry<K, V>> a set of the mappings.

equals

Added in API level 1
boolean equals (Object object)

Compares this 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.

Parameters
object Object: the object to compare with this object.
Returns
boolean true if the specified object is equal to this Map, false otherwise.

See also:

get

Added in API level 1
V get (Object key)

Returns the value associated with the specified key in this Hashtable.

Parameters
key Object: the key of the value returned.
Returns
V the value associated with the specified key, or null if the specified key does not exist.

See also:

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(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.

Returns
int this object's hash code.

isEmpty

Added in API level 1
boolean isEmpty ()

Returns true if this Hashtable has no key/value pairs.

Returns
boolean true if this Hashtable has no key/value pairs, false otherwise.

See also:

keySet

Added in API level 1
Set<K> keySet ()

Returns a set of the keys contained in this Hashtable. The set is backed by this Hashtable so changes to one are reflected by the other. The set does not support adding.

Returns
Set<K> a set of the keys.

keys

Added in API level 1
Enumeration<K> keys ()

Returns an enumeration on the keys of this Hashtable instance. The results of the enumeration may be affected if the contents of this Hashtable are modified.

Returns
Enumeration<K> an enumeration of the keys of this Hashtable.

See also:

put

Added in API level 1
V put (K key, 
                V value)

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 K: the key to add.
value V: the value to add.
Returns
V the old value associated with the specified key, or null if the key did not exist.

See also:

putAll

Added in API level 1
void putAll (Map<? extends K, ? extends V> map)

Copies every mapping to this Hashtable from the specified map.

Parameters
map Map: the map to copy mappings from.

remove

Added in API level 1
V remove (Object key)

Removes the key/value pair with the specified key from this Hashtable.

Parameters
key Object: the key to remove.
Returns
V the value associated with the specified key, or null if the specified key did not exist.

See also:

size

Added in API level 1
int size ()

Returns the number of key/value pairs in this Hashtable.

Returns
int the number of key/value pairs in this Hashtable.

See also:

toString

Added in API level 1
String toString ()

Returns the string representation of this Hashtable.

Returns
String the string representation of this Hashtable.

values

Added in API level 1
Collection<V> values ()

Returns a collection of the values contained in this Hashtable. The collection is backed by this Hashtable so changes to one are reflected by the other. The collection does not support adding.

Returns
Collection<V> a collection of the values.

Protected methods

rehash

Added in API level 1
void rehash ()

Increases the capacity of this Hashtable. This method is called when the size of this Hashtable exceeds the load factor.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.