title: Java getting the Enum name given the Enum Value
body: <p>How can I get the name of a Java Enum type given its value?</p>
  
  <p>I have the following code which works for a <strong>particular</strong> Enum type, can I make it more <strong>generic</strong>?</p>
  
  <pre><code>public enum Category {
  
      APPLE("3"), 
      ORANGE("1"), 
  
      private final String identifier;
  
      private Category(String identifier) {
          this.identifier = identifier;
      }
  
      public String toString() {
          return identifier;
      }
  
      public static String getEnumNameForValue(Object value){
          Category[] values = Category.values();
          String enumValue = null;
          for(Category eachValue : values) {
              enumValue = eachValue.toString();
  
              if (enumValue.equalsIgnoreCase(value)) {
                  return eachValue.name();
              }
          }
          return enumValue;
      }
  }
  </code></pre>