title: Filling ArrayList vs LinkedList
body: <p>I have been thinking that <code>LinkedList</code> fills faster than <code>ArrayList</code>. As I know <code>ArrayList</code> is based on simple array with limited length(constant). So every time array is out of range, new array with higher range will be created. <code>LinkedList</code> is much simpler. It hasn't got any limit (except for memory), so it should be filled faster. But I run next code:</p>
  
  <pre><code> public static void main(String[] args) {
          int length = 7000000;
  
          List&lt;Integer&gt; list = new LinkedList&lt;Integer&gt;();
          long oldTime = System.currentTimeMillis();
          for (int i = 0; i &lt; length; i++) {
              list.add(i);
          }
          System.out.println("LinkedList fill: " + (System.currentTimeMillis() - oldTime));
  
          list = new ArrayList&lt;Integer&gt;();
          oldTime = System.currentTimeMillis();
          for (int i = 0; i &lt; length; i++) {
              list.add(i);
          }
          System.out.println("ArrayList fill: " + (System.currentTimeMillis() - oldTime));
      }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>LinkedList fill: 3936
  ArrayList fill: 628
  </code></pre>
  
  <p>Why so?</p>