Java: Enums
An enum
is a special "class" that represents a group of constants (unchangeable variables, like final
variables).
enum Level { LOW, MEDIUM, HIGH }
You can access enum
constants with the dot syntax:
Level myVar = Level.MEDIUM;
Loop Through an Enum
The enum type has a values()
method, which returns an array of all enum constants.
for (Level myVar : Level.values()) { System.out.println(myVar); } // Outputs LOW MEDIUM HIGH