title: ArrayList v.s. LinkedList - inserting time
body: <p>When I run (respectively):</p>
  
  <pre><code>package containers;
  
  import java.util.*;
  
      public static void main(String[] args) {
  
      List&lt;Integer&gt; arLst = new ArrayList&lt;Integer&gt;();
      List&lt;Integer&gt; lnLst = new LinkedList&lt;Integer&gt;();
  
      long start = System.currentTimeMillis();
  
      for (int i = 0; i &lt; 10000000; i++) {
          arLst.add(i);
      }
  
      System.out.println("Array list: "+Long.toString(System.currentTimeMillis()-start));
  
      start = System.currentTimeMillis();
  
      for (int i = 0; i &lt; 10000000; i++) {
          lnLst.add(i);
      }
  
      System.out.println("Linked list: "+Long.toString(System.currentTimeMillis()-start));
  }
  </code></pre>
  
  <p>I get roughly the same executing time.
  I know that Adding time should be faster for LinkedList.
  I wonder why.. (It makes sense that both for middle insertinon and last elemnt - since arrays know in O(1) where to insert, unlike LinkedList that has to go through the whole list, as I recall).</p>