Hard to find the exact problem because you do not include enough code to get your example to compile but one thing I notice is that your isInteger
method does not work. When I ran the input into your method it produced an empty stack for the integers. Use this instead:
public boolean isInteger(String str) {
try {
Integer.parseInt(str);
return true;
} catch (NumberFormatException ex) {
return false;
}
}
Alternatively I think you were attempting to use a Regex for determining if the string contains an integer. For that you would need to do this:
public boolean isInteger(String str) {
return str.matches("[0-9]+");
}
With either of these implementations of isInteger
I was able to get your code to run when I replace your stack with Stack<String>
collections. Hope that helps.