开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜