public enum Day
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}
public class EnumTest
{
public void display(Day day)
{
switch (day)
{
case FRIDAY:System.out.println("Fridays are better.");break;
case SATURDAY:System.out.println("SATURDAYS are better.");break;
case SUNDAY:System.out.println("SUNDAYS are best."); break;
default:System.out.println("Weekdays are bad");break;
}
}
public static void main(String[] args[])
{
for (Day d:Day.values())//for循环
{
print(d);//一次输出
}
}
}
{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}
public class EnumTest
{
public static void display(Day day)
{
switch (day)
{
case FRIDAY:System.out.println("Fridays are better.");break;
case SATURDAY:System.out.println("SATURDAYS are better.");break;
case SUNDAY:System.out.println("SUNDAYS are best."); break;
default:System.out.println("Weekdays are bad");break;
}
}
public static void main(String[] args)
{
for (Day d:Day.values())//for循环
{
display(d);//一次输出
}
}
}
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
Note that each enum type has a static values method that returns an array containing all of the values of the enum type in the order they are declared. This method is commonly used in combination with the for-each loop to iterate over the values of an enumerated type.