1、简单的枚举
public enum Day {
//名(值)
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY;//记住要用分号结束
}
public class Main {
public static void main(String[] args) {
System.out.println(Day.TUESDAY);
}
}
打印结果:
TUESDAY
2、带有描述的枚举
public enum Day {
//名(值)
MONDAY("周一"),
TUESDAY("周二"),
WEDNESDAY("周三"),
THURSDAY("周四"),
FRIDAY("周五"),
SATURDAY("周六"),
SUNDAY("周日");//记住要用分号结束
private String value;
private Day(String value){
this.value=value;
}
public String getValue() {
return value;
}
}
public class Main {
public static void main(String[] args) {
Day day =Day.TUESDAY;
System.out.println("英文名称:"+day.name());
System.out.println("汉语名称:"+day.getValue());
}
}
打印结果:
英文名称:TUESDAY
汉语名称:周二