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
2010-02-18 01:22:43
+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
2010-02-18 01:23:18
+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
2010-02-18 01:24:11
Thanks a lot... The java link that you posted was quite useful.
Arav
2010-02-18 04:27:30