This example shows how to iterate over hash table using enumerator:
//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");
//get Enumeration of values contained in Hashtable using
//Enumeration elements() method of Hashtable class
Enumeration e = ht.elements();
//iterate through Hashtable values Enumeration
while(e.hasMoreElements())
System.out.println(e.nextElement());
No comments:
Post a Comment