Core Java Tutorial

Core Java Tutorial

Hashtable Example program for elements()

[java]
/**
Author :candidjava.com
Description: Returns an enumeration of the values in this hashtable.
*/
import java.util.*;
import java.util.Hashtable;
import java.io.IOException;
public class HashtableElementsExample
{
public static void main(String args[])throws IOException
{
int s=33, s1=44,s2=55;
Enumeration e;
Hashtable h=new Hashtable();
h.put(1,s);
h.put(2,s1);
h.put(3,s2);
e=h.elements(); //returns the enumeration of values
while (e.hasMoreElements())
System.out.println(e.nextElement());
System.out.println(e);
}
}
[/java]

Output:

55
44
33