Here is an example of a string
expression I am creating that I then want to use in the condition of an if
statement.
public static String dynamicIf(String a, String b, String c){
String expression = "";
String[] list = {"one", "two", ""};
if(!a.equals(""))
expression += "a.equals(list[0])";
if(!b.equals(""))
{
if(!expression.equals(""))
expression += " && b.equals(list[1])";
else
expression += "b.equals(list[1])";
}
if(!c.equals(""))
{
if(!expression.equals(""))
expression += " && c.equals(list[2])";
else
expression += "c.equals(list[2])";
}
//String[] splitExpression = expression.split(" && ");
return expression;
}
So the function above creates a string which i would then like to use in the condition of an if
statement. The result of the method running with these parameters:
dynamicIf("one","two","");
is
a.equals(list[0]) && b.equals(list[1])
How can I get this expression in a string to run within the condition of an if
?
I hope you understand. Thank you.