I have set of constants like:
public static final String CONST1="abc";
public static final String CONST2="cde";
public static final String CONST3="ftr";
...................................
public static final String CONSTN="zya";
In an application, I need to check if some value is in some set of constants, like:
if (String val in [CONST1,CONST2,CONST3]) {
do something;}
else {
....
Is it possible to do this with enum? Or is it better use a set or an array?
Thanks.
What you need is Enum.valueOf()
Here is an example of what I usually do when working with Enums and might have “bad” data coming in.
you can also convert the
Arrayof values fromOption.values()into anEnumSetand search them and avoid the overhead of the possibleExceptionif you think it will be getting lots of bad data.