1

Are there Java libraries that can evaluate string expressions like "5+4*3" into a decimal number (or an integer, if there's no decimal part)? I could parse it myself, but then I'd also have to take the operator precedence into account which would complicate things

I have been writing a Swing calculator, mainly as a way to practice using IntelliJ IDEA's GUI Designer (discovered it only recently). I don't need anything fancy. As long as it supports the basic addition, subtraction, division, and multiplication, I'm fine with it. The expression string may have parentheses too

public class DefaultCalcProcessor implements CalcProcessor {
    @Override
    public double calculateResult(String expression) {
        // implementation goes here
    }
}

1 Answer 1

1

I did a quick Google search and found some candidates for your problem:

To me, probably the latter three seem to match your needs. Though, I haven't tested any myself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.