1
如何從指定的tag []數組中動態獲取枚舉的值。枚舉值獲取?
public enum TagName {
NAME("ASTON", null), ADDRESS("WER", null);
private String tagNameValue;
private String defaultValue;
public String getTagNameValue() {
return tagNameValue;
}
TagName(String header, String defaultValue) {
this.tagNameValue = header;
this.defaultValue = defaultValue;
}
public String getDefaultValue() {
return defaultValue;
}
}
public class MainExe {
public static void main(String[] args) {
String tag[] = { "NAME", "ADDRESS" };
String data = TagName.ADDRESS.getDefaultValue();
System.out.println(data);
// i want to fetch the value from the enum based on the tag value passed
// dynamically.
// something like this
for (int i = 0; i < tag.length; i++) {
String data = TagName.tag[i].getDefaultValue();
System.out.println(data);
}
}
}
得到它感謝,對(INT I = 0; I
klampo
2015-04-04 07:14:55