Java - Browsing a Vector using Enumeration

The example below shows how to browse and display all elements of Vector using the object Enumeration. Obtaining the list of items is done by calling the elements(), and to access an element, you need to invoke the nextElement().

import java.util.Enumeration; 
import java.util.Vector;

public class Iterate_Vector_Enumeration {

public static void main(String[] args) {
Vector vct = new Vector();
//add elements
vct.add("first");
vct.add("second");
vct.add("third");
vct.add("fourth");

Enumeration enm = vct.elements();
while(enm.hasMoreElements()){
System.out.println(enm.nextElement());
}
}
}
Runtime:

first
second
third
fourth