Iterate through values of Hashtable - Java Collection Framework

Java examples for Collection Framework:Hashtable

Description

Iterate through values of Hashtable

Demo Code


import java.util.Hashtable;
import java.util.Enumeration;
 
public class Main {
 
  public static void main(String[] args) {
   //from  w w w  . j ava2  s  .c  om
    //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.elements();
   
    //iterate through Hashtable values Enumeration
    while(e.hasMoreElements())
      System.out.println(e.nextElement());
  }
}

Result


Related Tutorials