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,
My solution, with manipulation of strings (not the fastest, but is compact):
public enum State {
NEW,
RUNNABLE,
BLOCKED,
WAITING,
TIMED_WAITING,
TERMINATED;
public static String[] names() {
String valuesStr = Arrays.toString(State.values());
return valuesStr.substring(1, valuesStr.length()-1).replace(" ", "").split(",");
}
}