I assume that (), {} and [] all have the same weight in terms of the order of operations, and you just need to change your code to allow all three interchangeably.
If so, I would simply use the matcher class with a simple regex check to see if the current char you are looking at is either a bracket, a curly bracket, or a bracket.
//convert char to string String temp += currentChar; //this will check for (, [, and { (need escapes because of how regex works in java) Pattern bracePattern = Pattern.compile("[\(\{\[]"); Matcher matcher = numPatt.matcher(temp); if(matcher.find()){ //you know you have a grouping character }
This code should allow you to find all opening wildcards (just replace (, {and [for),} and] in the regular expression to find the closing characters). This can be used in your isParenthesis () method.
source share