How do I read Vector object using Enumeration?

package org.kodejava.example.util;

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

public class VectorEnumeration {

    public static void main(String[] args) {
        Vector data = new Vector();
        data.add("one");
        data.add("two");
        data.add("three");

        StringBuilder sb = new StringBuilder("data: ");

        //
        // Get the enumeration of the vector and check if the
        // enumeration contains more elements.
        //
        for (Enumeration enumeration = data.elements(); 
             enumeration.hasMoreElements();) {
            sb.append(enumeration.nextElement()).append(",");
        }

        //
        // Delete the last ","
        //
        sb.deleteCharAt(sb.length() - 1);
        System.out.println(sb.toString());
    }
}
Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply