How to read all elements in vector by using Enumeration?

Below example shows how to iterate through vector using Enumeration object. We can get Enumeration object by calling hasMoreelements() method.

package test;

import java.util.Enumeration;
import java.util.Vector;
 
public class VectorEnumExample {
 
    public static void main(String a[]){
        Vector<String> vct = new Vector<String>();
        //adding elements to the end
        vct.add("Selenium");
        vct.add("Java");
        vct.add("UFT");
        vct.add("Other");
        Enumeration<String> enm = vct.elements();
        while(enm.hasMoreElements()){
            System.out.println(enm.nextElement());
        }
    }
}

Output:

Selenium
Java
UFT
Other

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site.
I welcome and value your comments, suggestions and corrections.

6451total visits,8visits today

The only business I know is learning new technology and spreading the knowledge. I believe sharing is learning. This is my prime reason to build this site. I welcome and value your comments, suggestions and corrections.