Is it possible to create ArrayList of enum values (and manipulate it)? For example:
enum MyEnum { ONE, TWO } MyEnum my = MyEnum.ONE; List > al = new
This is a more generic solution, that can be use for any Enum object, so be free of used.
static public List constFromEnumToList(Class enumType) { List nueva = new ArrayList(); if (enumType.isEnum()) { try { Class> cls = Class.forName(enumType.getCanonicalName()); Object[] consts = cls.getEnumConstants(); nueva.addAll(Arrays.asList(consts)); } catch (ClassNotFoundException e) { System.out.println("No se localizo la clase"); } } return nueva; }
Now you must call this way:
constFromEnumToList(MiEnum.class);