'Enumerating Strings in Java with For Loop

Having trouble getting this for loop w/ enumerated strings to compile, I don't know what I'm missing to make it work. I prefer using for (i = 0; i < 5; i++) {} but it doesn't work well for strings. Any advice is appreciated.

import java.util.*`



public class Main {

    public static void main(String args[])

    {

        Enumeration<String> Names;

        Vector<String> cNames = new Vector();
        Names.add("string1");

        Names.add("string2");

        Names.add("string3");

        Names.add("string4");

        Names.add("string5");
        Names = cNames.elements();
        for (Names : cNames.elements())
        {

            System.out.println(names);

        }

    }

}


Solution 1:[1]

Names is already defined in scope. You have Enumeration Names and Vector Names

you might want to name them differently, and naming convention should start with lower case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akin Okegbile