Junior — Middle
How can all possible values of an enum type be extracted?
sobes.tech AI
Answer from AI
In Java, to retrieve all values of an Enum, you can use the values() method, which returns an array of all enum constants. For example:
public enum Color {
RED, GREEN, BLUE;
}
public class Main {
public static void main(String[] args) {
for (Color color : Color.values()) {
System.out.println(color);
}
}
}
This code will output all the values of the Color Enum.