I have the following code including two operands and one operands converted from objects. Now I would like to merge them to an expression so that I can get a final answer. For example, the method receives 2,3,* and converts it to 2*3 and returns 6. Is there an easy way of solving this without using a lot of if and else if to check if its +,-,*,/ and so on.
private long calculateExpression(Object op1, Object op2, Object op){
long operand1 = Long.parseLong(String.valueOf(op1));
long operand2 = Long.parseLong(String.valueOf(op2));
Operator operator = Operator.toOperator(String.valueOf(op));
return answer;
}