枚举定义:
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");