java - Get enum based on addition value? -


this question has answer here:

i have enum defined such:

private static enum color {     black(color.black,"black"),     green(color.green,"green");      private color color;     private string name;      color(string n, color c) {         this.name = n;         this.color = c;     } 

im trying find way enum constant based on string (which second additional parameter. so, hypothetical example, id like

color.getenumfromstring("green") 

  public static color getenumfromstring(final string value) {         if (value == null) {             throw new illegalargumentexception();         }          (color v : values()) {             if (value.equalsignorecase(v.getvalue())) {                 return v;             }         }          throw new illegalargumentexception();     } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -