Hashtable
Hashtable was part of the original java.util and is a concrete
implementation of a Dictionary.
Hash table stores key/value pairs in a has table. In Hash table object
is used as a key, and the value is that which want linked to that key. The key
is then hashed, and the resulting hash code is used as the index at which the
value is stored within the table.
A Hash table can only store objects that override the hashcode(). This
method must compute and return the hash code for the object. The equals()
method is also override which compares two objects. These method defined by
object.
Constructors:
Hashtable()
Hashtable(int
size)
Hashtable(int size,float fillRatio)
Hashtable(Map m)
The first version is default constructor.
The second version creates a hash table that has an initial size
specified by size.
The third version creates a hash table that has an initial size
specified by size and a fill ratio specified by fillRatio.
The fourth version creates a hash table that is initialized with the
elements is m.
Method:
void clear()
Resets and empties the hash
table
boolean contains(Object value)
Returns true if some value equal to value exists within the hash table. Returns false if the value isn’t found.
boolean containsKey(Object key)
Returns true if some key equal to key exists
within the hash table. Returns false
if the key isn’t found.
boolean containsValue(Object value)
Returns true if some value equal to value exists within the hash table. Returns false if the value isn’t found.
Enumeration elements( )
Returns an enumeration of the values contained in the hash
table.
Object get(Object key)
Returns the object that contains the value associated with key.
If key is not in the hash table, a null object is
returned.
boolean isEmpty( )
Returns true if the hash table is empty;returns false if it contains at least one key.
Enumeration keys( )
Returns an enumeration of the keys contained in the hash table.
object get(object key)
Returns the object that contains the value
associated with key. If key is not in the hash table, a null object is
returned.
object Put(object
key,object value)
Inserts a key and a value into the hash
table. Returns null if key isn't allready in the hash table; returns the
previous value associated with key. If key is allready in the hash table.
void rehash()
Increases the size of the hash table and
rehashes all of its keys.
Object remove(object
key)
Removes
key and its value. returns the value associated with key. If key is not in the
hash table, a null object is returned.
Posted By : Ruchita Pandya
No comments:
Post a Comment