java get enum by ordinal

Solutions on MaxInterview for java get enum by ordinal by the best coders in the world

showing results for - "java get enum by ordinal"
Florencia
11 Oct 2016
1// Create your enum
2enum YourEnum {
3   enum1, enum2, enum3, enum4;
4   public static final YourEnum[] values = values();
5}
6
7// to get your enum by its ordinal, write this wherever in java
8YourEnum yourEnum = YourEnum.values[ordinal];
Alexander
03 Jul 2019
1YourEnum yourEnum = YourEnum.values()[ordinal];