Can I make an array of if statement conditions in Java?
807589Oct 2 2008 — edited Oct 3 2008I'm writing a Java program for a class where I need to take an array of data and test it for various conditions. These are the rules for the program. Rules are of the form "If *condition* do something. Conditions are things like array=0. I have about 20-30 of these different conditions.
I was wondering if there was a way in java to store all these conditions into an array and then loop through them? Something like this:
array[conditions]; //array of conditions
for(int i=0; i<array.length'i++)
{
if(array[i])
{
//do something in here
}
}
The problem is I don't know how to store these conditions so that they are evaluated. If I make it an array of strings (the conditions are stored as strings), I'm assuming Java won't actually evaluate that condition I have stored in a string?
Hope that description was somewhat clear. I'm just confused how I would go about checking a bunch of conditions/rules. I've spent a lot of time with Java over the years but I haven't used the language for the past 2 years so I'm a little rusty now. Any help would be greatly appreciated. Thanks.