List all values from an enum type in Java
Description
The following code shows how to list all values from an enum type.
Example
//w w w . j ava 2 s. c o m
enum Week {
Monday, Tuesday, Wednesday, Thursday, Friday, Saturaday, Sunday
}
public class Main {
public static void main(String args[]) {
System.out.println("Here are all Week constants");
// use values()
Week allWeek[] = Week.values();
for (Week aday : allWeek) {
System.out.println(aday);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »