标签:sum stat 逗号 pre this enum package rgs out
package enume;
import java.util.Arrays;
/**
*枚举类里的多个对象用逗号(,)分割,最后一个对象用分号结尾(";")
*/
enum Season1 {
SPRING("春天"),
SUMMER("夏天"),
AUTUMN("秋天"),
WINTER("冬天");
// 属性值
private final String seasonName;
//私有构造器
private Season1(String seasonName) {
this.seasonName = seasonName;
}
//获取属性名
public String getSeasonName() {
return seasonName;
}
}
public class EnumeDe002 {
public static void main(String[] args) {
// 静态方法values()获取枚举类里的所有对象名
Season1[] season = Season1.values();
System.out.println(Arrays.toString(season));
// 静态方法valueOf(String s)里的字符串必须为枚举类里的对象名
Season1 spring = Season1.valueOf("SPRING");
System.out.println(spring);
}
}
标签:sum stat 逗号 pre this enum package rgs out
原文地址:https://www.cnblogs.com/kukai/p/12598822.html