Java Utililty Methods Reflection Enum

List of utility methods to do Reflection Enum

Description

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

Method

ListgetEnumConstants(Class c)
Returns all Enum Constants in an Enum
return Arrays.asList(c.getEnumConstants());
String[]getEnumNames(Class> e)
get Enum Names
return Arrays.toString(e.getEnumConstants()).replaceAll("\\[|]", "").split(", ");
ListgetEnumValues(Class type)
It will parse the given Class as Enum , returns the list of values of given Enum
if (isEnum(type)) {
    Class<Enum> enumClass = (Class<Enum>) type;
    List<String> values = new ArrayList<>(enumClass.getEnumConstants().length);
    for (Enum anEnum : enumClass.getEnumConstants()) {
        values.add(anEnum.name());
    return values;
} else {
...
MapgetOptionsFromEnum(Class> enumClass)
Get the label and value for select options of forms from the given enum class.
Map<String, String> map = new HashMap<String, String>();
Enum<?>[] enumConstants = enumClass.getEnumConstants();
for (Enum<?> enumConstant : enumConstants) {
    map.put(enumConstant.toString(), getLabel(enumConstant.toString()));
return map;
booleanisLegalEnum(Class clazz, Object enuValue)
is Legal Enum
boolean result = false;
if (null == clazz || null == enuValue) {
    return result;
if (clazz.isEnum()) {
    Enum[] enums = (Enum[]) clazz.getEnumConstants();
    if (!isEmpty(enums)) {
        if (enuValue instanceof Enum) {
...
TypetoEnum(Class e, String s)
to Enum
try {
    return Type.valueOf(e, s);
} catch (IllegalArgumentException ex) {
    return null;
} catch (NullPointerException ex) {
    return null;
String[]toStrings(Class clenum)
to Strings
synchronized (strings) {
    String[] result = strings.get(clenum);
    if (result == null) {
        try {
            Enum<?>[] values = (Enum<?>[]) clenum.getMethod("values").invoke(null);
            result = new String[values.length];
            for (int i = 0; i < values.length; i++) {
                result[i] = values[i].toString();
...