public enum Code {
E1330("MERCOSUR (SOUTH AMERICAN COMMON MARKET)"),
E0257("Guinea Biss."),
E0252("Gambia");
private Code(String value){
setStringValue(value);
}
private Code (int value) {
setIntValue(value);
}
private int intValue;
private String stringValue;
public String getStringValue() {
return stringValue;
}
public int getIntValue() {
return intValue;
}
public void setStringValue(String value) {
this.stringValue = value;
}
public void setIntValue(int value) {
this.intValue = value;
}
}
如何获取值为“冈比亚”的代码的字段名称? - >这将是E0252
谢谢
答案 0 :(得分:4)
您可以通过循环搜索它:
String val = "Gambia";
String field = "";
for (Code c : Code.values())
if (c.getStringValue().equals(val)) {
field = c.name();
break;
}
System.out.println(field);
输出:
E0252