I have an Enum class, where each Enum has a String value.
I want to create a List<> with my Enum type from a List. Here the strings are the value of the enums.
Is it possible to assign them directly during initialization? If yes, what is the best way to do that?
here is an example code:
public class SomeController {
public enum MyEnum {
A("a"),
B("b"),
C("c");
private final String value;
MyEnum(String value) {
this.value = value;
}
}
public String handler(
@RequestParam(name = "enumList") List<MyEnum> myEnumList ) {
//do something with myEnumList
return "something";
}
}
P.S. I need to directly assign the String-list to MyEnum-list as above. I cannot do a loop on the String-list and add one by one.