title: Most efficient way to reverse a stack and add to an ArrayList
body: <p>I have two collections - an ArrayList and a Stack.  I use the stack because I needed some simple pop/push functionality for this bit of code. The ArrayList is essentially the out variable as this is a small section of code in the function.</p>
  
  <p>So, the variables are defined as such, then code is run to add elements to the stack.</p>
  
  <pre><code>ArrayList&lt;String&gt; out = new ArrayList&lt;String&gt;();
  
  /* other code.. */
  
  Stack&lt;String&gt; lineStack = new Stack&lt;String&gt;();
  
  /* code that adds stuff to the stack */
  </code></pre>
  
  <p>The question is, now that I have a fully populated stack, how do I place it in the out ArrayList in a reverse order then from the pop order.</p>
  
  <p>My first thought up solution was </p>
  
  <pre><code> while(!lineStack.empty()) {
       out.add(0, lineStack.pop());
   }
  </code></pre>
  
  <p>... which works, but I worry about the efficiency of adding an element to the beginning of the ArrayList (which forces all existing elements to need to shift.. it's a linked list (I believe).. big deal.. but still a concern). Also, I am running this through a loop... perhaps unnecessarily. </p>
  
  <p>So, my second solution that didn't involve looping (at least in my code, i'm sure the back end calls are doing it).</p>
  
  <pre><code> List l = lineStack.subList(0, lineStack.size());
   out.addAll(l);
  </code></pre>
  
  <p>I know I don't need to allocate the list, but it'll keep for cleaner code. However, I am not sure if this will give me a particularly helpful performance gain.</p>
  
  <p>So, my question is:  Which of these will likely be most efficient for SMALL to MEDIUM size sets? If there is a more efficient solution, what would it be?</p>