String equals() ==
1 public class Solution { 2 public int evalRPN(String[] tokens) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 Stack<Integer> stack = new Stack<Integer>(); 6 if(tokens == null || tokens.length == 0) 7 return 0; 8 for(int i = 0; i < tokens.length; i++){ 9 10 String str = tokens[i]; 11 if(str.equals("+")){ 12 int num1 = stack.pop(); 13 int num2 = stack.pop(); 14 stack.push(num1 + num2); 15 } 16 else if(str.equals("-")){ 17 int num1 = stack.pop(); 18 int num2 = stack.pop(); 19 stack.push(num2 - num1); 20 } 21 else if(str.equals("*")){ 22 int num1 = stack.pop(); 23 int num2 = stack.pop(); 24 stack.push(num1 * num2); 25 } 26 else if(str.equals("/")){ 27 int num1 = stack.pop(); 28 int num2 = stack.pop(); 29 stack.push(num2 / num1); 30 } 31 else 32 stack.push(Integer.valueOf(str)); 33 } 34 return stack.pop(); 35 } 36 }