package Basement;
enum Size{
SMALL("S"),MEDIUM("M"),LARGE("L");
private String abb;
private Size(String abb){
this.abb = abb;
}
public String getAbb(){
return this.abb;
}
}
public class Test {
public static void main(String[] args) {
//返回枚举常量名
System.out.println(Size.SMALL.toString()+"444"); //SMALL444
//toString的逆方法是valueOf(),将s设置为Size.ONLY
Size s = Enum.valueOf(Size.class, "LARGE");
System.out.println(s); //LARGE
//静态values()返回一个包含全部枚举值的数组
Size[] value = Size.values();
for(Size i:value)
System.out.println(i+"222"); //输出全部字符串+222
//ordinal()返回enum中枚举常量的位置
System.out.println(Size.MEDIUM.ordinal()); //1
}
}
enum Size{
SMALL("S"),MEDIUM("M"),LARGE("L");
private String abb;
private Size(String abb){
this.abb = abb;
}
public String getAbb(){
return this.abb;
}
}
public class Test {
public static void main(String[] args) {
//返回枚举常量名
System.out.println(Size.SMALL.toString()+"444"); //SMALL444
//toString的逆方法是valueOf(),将s设置为Size.ONLY
Size s = Enum.valueOf(Size.class, "LARGE");
System.out.println(s); //LARGE
//静态values()返回一个包含全部枚举值的数组
Size[] value = Size.values();
for(Size i:value)
System.out.println(i+"222"); //输出全部字符串+222
//ordinal()返回enum中枚举常量的位置
System.out.println(Size.MEDIUM.ordinal()); //1
}
}