How to get all enum values in Java?

Roman picture Roman · Feb 16, 2010 · Viewed 128k times · Source

I came across this problem that I without knowing the actual enum type I need to iterate its possible values.

if (value instanceof Enum){
   Enum enumValue = (Enum)value;
}

Any ideas how to extract from enumValue its possible values ?

Answer

ColinD picture ColinD · Feb 16, 2010
Object[] possibleValues = enumValue.getDeclaringClass().getEnumConstants();