Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java How To Loop Through an Enum?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ Level {Loop Through an Enum
The enum type has a values() method, which returns an array of all enum constants. This method is useful when you want to loop through the constants of an enum:
Example
enum Level {
LOW, MEDIUM, HIGH
}
public class Main {
public static void main(String[] args) {
for (Level myVar : Level.values()) {
System.out.println(myVar);
}
}
}