Java Program to Read Elements using Enumeration in Hashtable
The enumeration in java is one of the predefined interfaces, whose object is used for retrieving the data from collections framework variable(like Stack, Vector, HashTable, etc.) in a forward direction only and not in the backward direction.
HashTable is a class The hash table class implements a Map, which maps keys to values. It stores the key/value pair in the hash table. In this data structure we specify an object that is used as a key, and the value we want to associate with 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. HashMap doesn’t provide any Enumeration, while HashTable provides not fail-fast Enumeration. The hierarchy of the hash table is as follows:
public class Hashtable<K,V> extends Dictionary<K,V> implements Map<K,V>, Cloneable, Serializable
- K: Keys inserted.
- V: Values assigned to the keys.
In order to create HashTable, import hash Table from java.util.Hashtable where, K, V are of data types like integer, string, float, etc.
Syntax: Creating hash Table
Hashtable<K, V> ht = new Hashtable<K, V>();
Implementation: College Student Information
Value of Name is: Bahubali Value of College is: Amarnath Value of Department is: Vedics Value of Name is: Ravaan Value of College is: SriLanka Value of Department is: CS Value of Name is: Kattappa Value of College is: Beardo Value of Department is: War
Please Login to comment...