标签:style blog color os java for sp div log
枚举定义:
public enum SizeEnum { SMALL, BIG, BIGEST };
public enum SizeStringEnum { SMALL("小"), BIG("大"), BIGEST("巨大"); private String strSizeString; public String toString() { return strSizeString; } private SizeStringEnum(String str) { this.strSizeString = str; } }
常用方法:
1、values():
获取当前枚举的所有对象属性:
如:
//1、 SizeStringEnum sizeStringEnum=SizeStringEnum.BIG; for(SizeStringEnum size: sizeStringEnum.values()) { System.out.println(size); } //2、 for(SizeStringEnum size: SizeStringEnum.values()) { System.out.println(size); }
2、Enum.valueOf
通过枚举值寻找枚举对象
sizeStringEnum=Enum.valueOf(SizeStringEnum.class, "BIG");
Rhythmk 一步一步学 JAVA (18): Enum枚举学习
标签:style blog color os java for sp div log
原文地址:http://www.cnblogs.com/rhythmK/p/4051965.html