How to Use Enumeration to Display Elements of Hashtable in Java? Last Updated : 18 Nov, 2021 Comments Improve Suggest changes Like Article Like Report Hashtable class implements a hash table, which maps keys to values. Any non-null object can be used as a key or as a value. To successfully store and retrieve objects from a hashtable, the objects used as keys must implement the hashCode method and the equals method. Now here we can get the keys and values of a Hashtable as an Enumeration object using keys() and elements() method. We can obtain all keys and values respectively as an Enumeration object using Enumeration methods like hasMoreElements() and nextElement() we can read all keys and values corresponding to a Hashtable. Example 1: Java // Java Program to Demonstrate Getting Values // as an Enumeration of Hashtable class import java.io.*; import java.util.Enumeration; import java.util.Hashtable; // Main class // EnumerationOnKeys public class GFG { // Main driver method public static void main(String[] args) { // Creating an empty hashtable Hashtable<Integer, String> ht = new Hashtable<Integer, String>(); // Inserting key-value pairs into hash table // using put() method ht.put(1, "Geeks"); ht.put(2, "for"); ht.put(3, "Geeks"); // Now creating an Enumeration object // to read elements Enumeration e = ht.elements(); // Condition holds true till there is // single key remaining // Printing elements of hashtable // using enumeration while (e.hasMoreElements()) { // Printing the current element System.out.println(e.nextElement()); } } } OutputGeeks for Geeks Example 2: Java // Java Program to Demonstrate Getting Keys // as an Enumeration of Hashtable class // Importing required classes import java.io.*; import java.util.*; // Main class class GFG { // Main driver method public static void main(String[] args) { // Creating an empty hashtable Hashtable<String, String> ht = new Hashtable<String, String>(); // Inserting key-value pairs into hash table // using put() method ht.put("Name", "Rohan"); ht.put("Age", "23"); ht.put("Address", "India"); ht.put("Article", "GeeksforGeeks"); // Now creating an Enumeration object // to store keys Enumeration<String> e = ht.keys(); // Condition holds true till there is // single key remaining while (e.hasMoreElements()) { // Getting key String key = e.nextElement(); // Printing key and value corresponding to // that key System.out.println(key + ":" + ht.get(key)); } } } OutputName:Rohan Article:GeeksforGeeks Age:23 Address:India Comment More infoAdvertise with us Next Article How to Use Enumeration to Display Elements of Hashtable in Java? R rohanchopra96 Follow Improve Article Tags : Java Java Programs Java-HashTable Practice Tags : Java Similar Reads 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 3 min read How to Convert a HashTable to Other Collections Types in Java? In Java, a Hashtable is a data structure that stores the data in the form of key and value pairs. And each key is mapped to a specific value. It implements the Map interface. HashTable provides a simple way to access the data using the unique keys. In this article, we will learn how to convert a Has 3 min read How to Get Elements By Index from HashSet in Java? HashSet extends AbstractSet and implements the Set interface. It creates a collection that uses a hash table for storage. The class does not guarantee the constant order of elements over time but permits the null element. The underlying data structure for HashSet is Hashtable. HashSet also implement 3 min read How does HashTable Handle HashCode Distribution in Java? Key-value pairs that are mapped from keys to values using a hash function are stored in Java databases using hash tables. The distribution of hash codes, which guarantees effective element retrieval and storage, is one of a hash table's most important features. In this article, we will learn about h 3 min read How to Convert List of Lists to HashSet in Java? In Java, Collections like lists, and sets play a crucial role in converting and manipulating the data efficiently. The Conversion of a List of Lists into a HashSet is mainly used to Remove Duplicates and ensures the programmer maintains the unique data of elements. Example to Convert List of Lists t 2 min read Like