Get index of enum from string?

前端 未结 5 1353
暗喜
暗喜 2021-01-07 17:55

I have a string value, I also have an array of strings and an enum containing the range also. To get the index of the string in the array, from the value supplied I write th

5条回答
  •  再見小時候
    2021-01-07 18:33

    I might not understand you question, but the same code works for enums too:

    int index = Arrays.asList(YourEnum.values()).indexOf(YourEnum.ENUM_ITEM);
    

    Or you can get:

    int index = YourEnum.valueOf("ENUM_ITEM").ordinal();
    

提交回复
热议问题