There is no standard Java class or method that will do what you want. Your options include:
Select and use some third-party expression evaluation library. For example JEL or any of the half dozen libraries listed here.
Wrap the expression in the Java source code for a class with an
eval
method, send that to the Java compiler, and then load the resulting compiled class.Use some scripting language that can be called from Java as an expression evaluator. Possibilities include Javascript, BeanShell, and so on.
Write your own expression evaluator from scratch.
The first approach is probably simplest. The second and third approaches are a potential security risk if you get the expression to be evaluated from an untrusted user. (Think code injection.)