Get index of enum from string?

前端 未结 5 1351
暗喜
暗喜 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:17

    Not sure if I understand you correctly but based on question title you may be looking for

    YourEnum.valueOf("VALUE").ordinal();
    
    1. YourEnum.valueOf("VALUE") returns enum value with name "VALUE"
    2. each enum value knows its position (indexed from zero) which we can get by calling ordinal() method on it.

提交回复
热议问题