What\'s the easiest and/or shortest way possible to get the names of enum elements as an array of String
s?
What I mean by this is that if, for example,
Create a String[]
array for the names and call the static values()
method which returns all the enum values, then iterate over the values and populate the names array.
public static String[] names() {
State[] states = values();
String[] names = new String[states.length];
for (int i = 0; i < states.length; i++) {
names[i] = states[i].name();
}
return names;
}