0

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);

        }

    }

}
knittl
  • 246,190
  • 53
  • 318
  • 364
Squilly
  • 27
  • 1
  • 6

1 Answers1

0

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.

Akin Okegbile
  • 1,108
  • 19
  • 36
  • I edited it, missed a typo from my IDE code. Stack Overflow doesn't show my s after "Enumeration" & "Vector" either – Squilly Oct 03 '17 at 22:06
  • You want to instantiate Your typed enumeration. `Enumeration Names = new Enumeration() {}` – Akin Okegbile Oct 03 '17 at 22:13
  • This question talks about List of Enums Which is what i assume you're trying to do . A Vector of Enum values https://stackoverflow.com/questions/2849529/java-enum-list-from-class – Akin Okegbile Oct 03 '17 at 22:25