Possible Duplicate:
Evaluating a math expression given in string form
How can I boolean evaluate a string containing bool expressions? Like:
String userVar[] = {"a = 1", "b = 1", "c = 0"};
String expr = "a & b & c";
boolean result = evaluate(expr); //would evaluate to false
The user should be able to define his own variables (a = 1), and define his own boolean expression (a & b & c). So I will have all expressions only as a string. How can I evaluate them?
You can use a ScriptEngine as commented by Nambari:
prints 0.
Also note that the expression is not a boolean expression but a bitwise operation.