- Hashtable Class implements Map, Cloneable in addition to Serializable interfaces in addition to likewise extends Dictionary class.
- It maps keys to values inwards tabular array format. Every fundamental is linked to it's value.
- In Hashtable, whatever object which is not naught volition last used every bit a fundamental or it's value.
- Initial capacity in addition to charge gene are 2 parameters of Hashtable that deport upon its performance.
- Meaning of capacity is the release of buckets inwards Hashtable in addition to Meaning of initial capacity is release of buckets inwards Hashtable at the fourth dimension of its creation.
- Load gene is parameter which mensurate how much amount Hashtable is in addition to when to increment it's capacity automatically.
- In social club to successfully cry back in addition to shop object inwards Hashtable, the object which is used every bit fundamental must implement the equals in addition to the hashCode methods.
Important methods of Hashtable Class are given below.
- void clear() : It volition take all fundamental in addition to it's values from Hashtable.
- Object clone() : It volition exercise in addition to provide shallow re-create of this hashtable.
- boolean contains(Object value) :It volition banking concern fit inwards Hashtable for whatever fundamental maps to the specified value.
- boolean containsKey(Object key) : It volition banking concern fit if whatever fundamental is available inwards Hashtable which is same every bit specified object.
- boolean containsValue(Object value) : It volition provide truthful if Hashtablehas whatever fundamental which maps to specified value.
- Enumeration<V> elements() : Returns an enumeration of the values inwards this Hashtable.
- Set<Map.Entry<K,V>> entrySet() : It volition provide laid upwards persuasion of Hashtable alongside mapping.
- boolean equals(Object o) : It volition banking concern fit in addition to compare given object alongside map for equality.
- V get(Object key) : It volition provide value which is mapped alongside specified fundamental inwards map. Return naught if no mapping found.
- int hashCode() : It volition provide has code value for this map.
- boolean isEmpty() : It volition banking concern fit if Hashtable is empty in addition to no mapping found.
- Enumeration<K> keys() : It volition returns an enumeration of the keys inwards this Hashtable.
- Set<K> keySet() : It volition provide laid upwards persuasion of keys contained inwards this map.
- V put(K key, V value) : Map in addition to insert specified fundamental alongside value inwards map.
- void putAll(Map<? extends K,? extends V> t) : It volition re-create all key-values mapping from specified map to this map.
- protected void rehash() : It volition increases the capacity of in addition to internally reorganizes this Hashtable, inwards social club to adapt in addition to access its entries to a greater extent than efficiently.
- V remove(Object key) : It volition take specified fundamental in addition to its mapped value from
- int size() : It volition provide size of Hashtable.
- Collection<V> values() : It volition provide collection persuasion of map.
I convey created sample illustration for Hashtable to demo usage of basic methods.
HashTableExample
package JAVAExamples; import java.util.Hashtable; import java.util.Map; world shape HashTableExample { world static void main(String[] args) { Hashtable<Integer, String> ht = novel Hashtable<Integer, String>(); ht.put(1000, "London"); ht.put(1001, "Mumbai"); ht.put(1002, "Chicago"); ht.put(1003, "Tokyo"); ht.put(1004, "Paris"); ht.put(1005, "Moscow"); ht.put(1006, "Berlin"); for (Map.Entry m : ht.entrySet()) { System.out.println(m.getKey() + " " + m.getValue()); } //Check if at that topographic point is whatever fundamental inwards map which maps to specified value. System.out.println("Map has whatever fundamental for Chicago? : "+ht.contains("Chicago")); //Check if specified fundamental is available inwards map. System.out.println("Map has fundamental 1009? : "+ht.contains(1009)); //Get size of map System.out.println("Map size is : "+ht.size()); } }
Output :
1004 Paris 1003 Tokyo 1002 Chicago 1001 Bombay Map has whatever fundamental for Chicago? : truthful Map has fundamental 1009? : imitation Map size is : 7