public enum ColorEnum {
RED("red","红色"),GREEN("green","绿色"),BLUE("blue","蓝色");
private final String key;
private final String value;
ColorEnum(String key, String value) {
this.key = key;
this.value = value;
}
public static ColorEnum getEnumByKey(String key){
if(null == key){
return null;
}
for(ColorEnum temp:ColorEnum.values()){
if(temp.getKey().equals(key)){
return temp;
}
}
return null;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public static final Map<String,String> map = new HashMap();
static{
for (ColorEnum colorEnum : ColorEnum.values()) {
map.put(colorEnum.getKey(),colorEnum.getValue());
}
}
}
public class EnumTest {
public static void main(String[] args) {
Map<String, String> map = ColorEnum.map;
System.out.println(args.length);
Set<Map.Entry<String, String>> entrySet = map.entrySet();
for (Map.Entry<String, String> entry : entrySet) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
}
}