Home » Core Java » util » Hashtable » Hashtable keys Iterator example

About Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Hashtable keys Iterator example

In this example we shall show you how to obtain a Hashtable keys Iterator, that is an iterator of the keys of the Hashtable. To obtain a Hashtable keys Iterator one should perform the following steps:

  • Create a new Hashtable.
  • Populate the hashtable with elements, using put(K key, V value) API method of Hashtable.
  • Invoke keys() API method of Hashtable. It returns an Enumeration of the keys contained in the Hashtable.
  • Iterate through the enumeration, with hasMoreElements() and nextElement() API method of Enumeration,

as described in the code snippet below.

package com.javacodegeeks.snippets.core;
import java.util.Hashtable;
import java.util.Enumeration;
public class HashtableKeysIterator {
  public static void main(String[] args) {
    // Create a Hashtable and populate it with elements
    Hashtable hashtable = new Hashtable();
    // Enumeration keys() operation returns an Enumeration of keys contained in Hashtable
    Enumeration keysEnumeration = hashtable.keys();
    // Iterate through Hashtable keys Enumeration
    System.out.println("Hashtable keys : ");



Hashtable keys : 

This was an example of how to obtain a Hashtable keys Iterator in Java.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....


Receive Java & Developer job alerts in your Area


Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments