public int evalRPN(String[] tokens){
  if (tokens == null || tokens.length == 0)   return 0;
  Stack<String> s=new Stack<String>();
  int len=tokens.length;
  for (int i=0; i < len; i++) {
    String cur=tokens[i];
    if (isOperator(cur)) {
      int t2=Integer.parseInt(s.pop());
      int t1=Integer.parseInt(s.pop());
      int res=calculate(t1,t2,cur);
      s.push(Integer.toString(res));
    }
 else     s.push(cur);
  }
  return Integer.valueOf(s.peek());
}

public int evalRPN ( String [ ] tokens ) { if ( tokens == null || tokens . length == 0 ) return 0 ; Stack < String > s = new Stack < String > ( ) ; int len = tokens . length ; for ( int i = 0 ; i < len ; i ++ ) { String cur = tokens [ i ] ; if ( isOperator ( cur ) ) { int t2 = Integer . parseInt ( s . pop ( ) ) ; int t1 = Integer . parseInt ( s . pop ( ) ) ; int res = calculate ( t1 , t2 , cur ) ; s . push ( Integer . toString ( res ) ) ; } else s . push ( cur ) ; } return Integer . valueOf ( s . peek ( ) ) ; }
assign a priority for each operators use a stack to store them note the numbers can be negative we evaluate the expression left - to - right and push operands onto the stack until we encounter an operator , which we pop the top two values from the stack . we then evaluate the operator , with the values as arguments and push the result back onto the stack .
