Java Utililty Methods Enum from Ordinal

List of utility methods to do Enum from Ordinal

Description

The list of methods to do Enum from Ordinal are organized into topic(s).

Method

EfromOrdinal(Class enumClass, int ordinal)
from Ordinal
E[] enumArray = enumClass.getEnumConstants();
return enumArray[ordinal];
TfromOrdinal(Class enumClass, Integer value)
Get the enum value from its ordinal value
Enum<T>[] values = (enumClass).getEnumConstants();
if (value > values.length - 1 || value < 0) {
    throw new IllegalArgumentException(
            "Wrong value provided for the enum " + enumClass + " : " + value + "!");
return (T) values[value];
EfromOrdinal(E[] values, int ordinal)
from Ordinal
return ordinal >= 0 && ordinal < values.length ? values[ordinal] : values[0];