Iterate through keys of Hashtable - Java Collection Framework

Java examples for Collection Framework:Hashtable

Description

Iterate through keys of Hashtable

Demo Code


import java.util.Hashtable;
import java.util.Enumeration;
 
public class Main {
 
  public static void main(String[] args) {
   /*w w w . j  a v a 2  s  . c o m*/
    //create Hashtable object
    Hashtable ht = new Hashtable();
   
    //add key value pairs to Hashtable
    ht.put("1","One");
    ht.put("2","Two");
    ht.put("3","Three");
   
    Enumeration e = ht.keys();
   
    //iterate through Hashtable keys Enumeration
    while(e.hasMoreElements())
      System.out.println(e.nextElement());
  }
}

Result


Related Tutorials