0

I have a enum clas like this.

public static enum Industries {
    A("Apparel"),
    B("Bags"),
    C("Clothes"),
    D("Diapers");

    private String value;

    Industries(String val){
        this.value = val ;
    }       
    public String getValue(){
        return value;
    }   
}   

The enum values are show in a combo box on front end. If Clothes is selected, C is stored in the db.

In another search form, when I execute some sql query, the value C is returned for industries. I want to use the value C, to get values'clothes' to be shown instead of C.

If bags was selected in combo box, I want bags to be shown in search form results instead of B. How do i do it?

  • 1
    First `private final String value` - fields in an `enum` should be `final`. As to your problem, The user selects "Bags", that gives you the `String` "`C`" from the frontend. You store that "`C`" as a (`VARCHAR`?) in your database. When you query that back you get a `String` "`C`" - you just need to call `Industries.valueOf(input)` to get back the original `enum` value, then you can call `getValue()`. – Boris the Spider Feb 24 '18 at 09:27
  • Once you look up the enum by string value, getting description is a simple method call. – Sergey Kalinichenko Feb 24 '18 at 09:34

0 Answers0