Is there an easy way to take a String such as "5*4" and return 20?
The most simple way would be to use the Rhino JavaScript engine available with the JRE 6 standard API.
Edit: as per the comments, if the strings are user-supplied, this could be a potential security hole. Be sure to filter out everything except digits, braces and mathematical operators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With