title: Method to copy a stack into a new one and return it without changing the original stack using a single queue using standard API classes
body: <p>Ok, so I tried making a method that does what I wrote in the title. It should be pretty clear to see what's happening. However, I feel like I'm making it more complicated than it should be. I copy the stack into the queue, resulting in it being backwards: <code>[4,3,2,1]</code><br>
  Then I copy it back into the stack, and then back into the queue so that I can get it in proper order: <code>[1,2,3,4]</code><br>
  Then I peek into the copiedStack, and remove into the original stack.<br>
  Then I return the copiedStack.
  My main method prints this:<br>
  <code>[1,2,3,4]
  [1,2,3,4]</code></p>
  
  <p>^ (btw, anyone know how to properly align the code above? it's annoying me)</p>
  
  <p>So is there a simpler implementation?</p>
  
  <p>The methods I can use are here:<br>
  <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/Queue.html</a>
  <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html</a></p>
  
  <pre><code>import java.util.*;
  
  public class Question2Stack {
    public static void main(String[] args) {
      Stack&lt;Integer&gt; stack = new Stack&lt;Integer&gt;();
      stack.push(1);
      stack.push(2);
      stack.push(3);
      stack.push(4);
      System.out.println(copyStack(stack));
      System.out.println(stack);
    }
  
    public static Stack&lt;Integer&gt; copyStack(Stack&lt;Integer&gt; stack) {
      Stack&lt;Integer&gt; copiedStack = new Stack&lt;Integer&gt;();
      Queue&lt;Integer&gt; q = new LinkedList&lt;Integer&gt;();
      while (!stack.isEmpty()) {
        q.add(stack.pop());
      }
      while (!q.isEmpty()) {
        stack.push(q.remove());
      }
      while (!stack.isEmpty()) {
        q.add(stack.pop());
      }
      while (!q.isEmpty()) {
        copiedStack.push(q.peek());
        stack.push(q.remove());
      }
      return copiedStack;
    }
  }
  </code></pre>