title: ArrayDeque vs ArrayList to implement a stack
body: <p>The documentation for <code>ArrayDeque</code> says:</p>
  
  <blockquote>
    <p>This class is likely to be faster than Stack when used as a stack, and faster than LinkedList when used as a queue.</p>
  </blockquote>
  
  <p>There is no mention of the difference between using an <code>ArrayDeque</code> as a stack and using an <code>ArrayList</code>. You can use an <code>ArrayList</code> as a stack as follows.</p>
  
  <pre><code>list.add(object);                      // push
  object = list.remove(list.size() - 1); // pop
  </code></pre>
  
  <p>I found that when I used an <code>ArrayList</code> in this way only, its performance is worse than <code>ArrayDeque</code>. What accounts for this difference? Surely, it can't just be the calls to <code>size()</code>? Internally, both <code>ArrayList</code> and <code>ArrayDeque</code> are implemented using an <code>Object[]</code> that is replaced by a larger array when required, so surely the performance should be about the same?</p>