I have a method that\'s supposed to validate accurate opening and closing parenthesis in a string using java. This method will be used to parse mathematical expressions so it\'s
The immediate problem is this
String[] tokens = str.split("");
Gives you first char = "" if you use java 1.7
or less, so you will exit your loop since stack is empty...
Note: this has been changed in java 1.8
split difference between java 1.7 and 1.8
change to:
char[] tokens = str.toCharArray();
I guess however that you need to consider the fact that there can be chars before your first (
and that you may have other chars then (
and )