I want to convert some String
to an operator like this:
int value = 1;
int valueToCompare = 3;
String operation = \"<\";
if (value operation
You can use ScriptEngine for that, works for any other JavaScript expressions also :
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
int value = 1;
int valueToCompare = 3;
String operation = "<";
if ((Boolean)engine.eval("" + value + operation + valueToCompare)) {
System.out.println("Here we are.");
}