创建枚举类
package com.ywlaker.enums; /** * @功能描述:季节枚举类 * @author yang.wei * @time 2015年9月1日 上午11:56:23 * @version 0.0.1 */ public enum Season { SPRING("春天","spring"), SUMMER("夏天","summer"), AUTUMN("秋天","autumn"), WINTER("冬天","winter"); private String index; private String name; private Season(String name, String index) { this.name = name; this.index = index; } public static String getName(String index) { for (Season s : Season.values()) { if (s.getIndex().equals(index)) return s.getName(); } return null; } public String getIndex() { return index; } public void setIndex(String index) { this.index = index; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
遍历枚举类
public static String getName(String index) { for (Season s : Season.values()) { if (s.getIndex().equals(index)) return s.getName(); } return null; }
时间: 2024-10-07 07:43:05