title: java stack reading from an array throws ArrayIndexOutOfBoundsException
body: <p>I need to fill a stack from an array, then print out the elements in order and then again reversing the order. What I'm having problems with is I'm getting an ArrayIndexOutOfBoundsException and cant figure out where it is coming from. I have tried running through the debug and it appears as I'm popping off elements it never reaches the last element. Below is my code:</p>
  
  <pre><code>public class arrayStack {
  
      private int top;
      private String[] storage;
  
      public arrayStack(int capacity)
      {
          storage = new String[capacity];
          top = -1;
      }
  
      public boolean isEmpty() {
          return (top == 0);
      }
  
      String peek() {
          return storage[top];    
      }
  
      String pop() {
          top--;
          return storage[top];
      }
  
      public void push(String str) {
          top++;
          storage[top] = str;
      }
  
  }
  </code></pre>
  
  <p>StackMain.java:</p>
  
  <pre><code>public class StackMain {
  
      public static void main(String[] args) {
          //int j = 5;
          String[] list = new String[5];
  
          list[0] = "Beware";
          list[1] = "The";
          list[2] = "Ides";
          list[3] = "Of";
          list[4] = "March";
  
          arrayStack stack = new arrayStack(5);
  
          for(int i = 0; i &lt; list.length; i++)
          {
              stack.push(list[i]);
          }
  
          for(int j = 0; j &lt; list.length; j++)
              System.out.println(stack.pop());
  
      }
  
  }
  </code></pre>