tags:

views:

41

answers:

3

I have a lot of static values "ABC" , "DEF" , "FGH" ,"IJK", "JKL" I want to have an if condition that checks whether the a String variable exists in this list of static values. I dont want to have too many or conditions. what is a better way of doing it?

A: 

Create a static array of strings. Also java enum is a good idea.

fastcodejava
+1  A: 

Not sure what language you're using, but you could put those values into an array, and then do a search on the array to see if the value you're matching exists anywhere in the array.

jaywon
+2  A: 

If you are using PHP you can use the in_array function. Just put all the static values in an array and see if the string is in the array using the function.

If you are using Java then I would recommend checking this thread out.

twodayslate
Thanks a lot... The java link that you posted was quite useful.
Arav