title: Parentheses matching using stacks and java
body: <p>Here's my code for matching parentheses.THe problem is it always returns false.<br>
  I can't see where the mistake is.<br>
  topAndpop() returns the top value of the stack and its of type Object.<br>
   Can someone please show me the mistake.</p>
  
  <pre><code>public class Matching {
      ArrayStack match_Stack=new ArrayStack();
      Object popped;
      String[] array_match={"{","{","}","}"};
      public boolean matching() throws OverFlowException,EmptyStackException {
          boolean isMatch=false;
          for(int i=0;i&lt; array_match.length;i++) {
              if (array_match[i].equals("{") || array_match[i].equals("[") ||array_match[i].equals("("))   
                  match_Stack.push(array_match[i]);
  
              if(array_match[i].equals("}") || array_match[i].equals("]") ||array_match[i].equals(")") )  {
                  if (match_Stack.isEmpty())
                      return false;
                  if  (String.valueOf(match_Stack.topAndpop()).equals(String.valueOf(array_match[i]))) {
  
                      isMatch=true;
                  } else {
                      isMatch=false;
                      return isMatch;
                  }
              }
          }   
          return isMatch; 
      }
  
      public static void main (String args[]) throws EmptyStackException,OverFlowException {
          Matching a=new Matching();
          System.out.println(a.matching());
      }
  }
  </code></pre>