I have the following enum, it contains label and field values. I would like to return the field by passing in the label name.
Can anyone make any suggestions?
public enum Table (
NAME("name", "FULL_NAME");
public final String label;
public final String field;
private Table(String label, String field) {
this.label = label;
this.field = field;
}
}
public static String fieldByLable(String label) { String result = null; for(Table i: Table.values()) { if( i.lable.equals(label) ) { result = i.field; break;} } retrurn result; }and then simplyString value = Table.fieldByLable("name"); In any case, you need Map forget about enum, for this scenario.