title: calling on a stack inside a while loop
body: <p>i can't figure out why this part of my program won't work, I peek outside the while loop and confirm that the stack is not empty, yet when i try to access it inside the while loop I get this error:</p>
  
  <blockquote>
    <p>"Exception in thread "main" java.util.EmptyStackException    at
    java.util.Stack.peek(Unknown Source)"</p>
  </blockquote>
  
  <p>here's the relevant piece of code</p>
  
  <pre><code>String test = list.peek();
      System.out.println(test);
      while(list.peek() != null)
      {
          temp = list.pop();
  </code></pre>
  
  <p>There's more too the while loop but it breaks once <code>list.peek</code> is called inside the parenthesis, I tried changing it to "<code>while(test != null)</code>" for test purposes but it breaks once it gets to <code>list.pop()</code></p>