title: EmptyStackException error with Stack in Java
body: <p>What I'm trying to do is to get the eval variable to have each of its letters put into a stack and then printed out. I'm getting an EmptyStackException error(assuming that means that there isn't anything in the stack). What I don't understand is that I thought that the eval string was put into the variable stack. Why is it empty?</p>
  
  <pre><code>public static void main(String[] args)
  {
  
     Stack&lt;String&gt; variable = new Stack&lt;String&gt;();
  
     String eval = StdIn.readString();
     String alphabet = "abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
  
     for (int i = 0; i &lt; eval.length(); i++)
     {
         eval = eval.substring(i,i);
  
         if (eval.equals(alphabet.substring(0, 52)))// checks if eval is equal to any letter of alphabet
       {
             variable.push(eval);
  
         System.out.println(variable.pop());
       }
     } 
    }
  }
  </code></pre>
  
  <p>Im using eclipse</p>
  
  <hr>
  
  <p>Sample Runs:</p>
  
  <pre><code>input: hello
  Exception in thread "main" java.util.EmptyStackException
  at java.util.Stack.peek(Unknown Source)
  at java.util.Stack.pop(Unknown Source)
  at eval.main(eval.java:31)
  </code></pre>