开发者

Help with enum in java

开发者 https://www.devze.com 2023-03-08 06:05 出处:网络
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 i

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

精彩评论

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

关注公众号