Help with enum in java
I have an enum that looks like this
public enum MyStates {
开发者_开发技巧 FIRST,
SECOND,
THIRD,
}
Every time I access them it prints it by the names I have given them. Is there a way to get their indexes? Ex. FIRST would be = 1, and so forth. Thanks
Related:
Enum with int value in Java
Use the ordinal()
function.
MyStates.FIRST.ordinal();
精彩评论