Enumerate through a Vector using Enumeration - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Enumerate through a Vector using Enumeration

Demo Code


 
import java.util.Vector;
import java.util.Enumeration;
 
public class Main {
 
  public static void main(String[] args) {
    //create a Vector object
    Vector v = new Vector();
   /*from w ww.ja  va2s  .c  o  m*/
    //populate the Vector
    v.add("One");
    v.add("Two");
    v.add("Three");
    v.add("Four");
   
    //Get Enumeration of Vector's elements using elements() method
    Enumeration e = v.elements();
   
    System.out.println("Elements of the Vector are : ");
   
    while(e.hasMoreElements())
      System.out.println(e.nextElement());
  }
}

Result


Related Tutorials