title: ArrayList shows different time of execution each time why?
body: <p>I was working with <code>ArrayList</code> and trying to add <code>new object</code> at starting of <code>ArrayList</code> of a prepopulated <code>ArrayList</code> having <code>3000000</code> record all ready.</p>
  
  <p>According to my knowledge it will add new object at first index and move all record below to their previous position. And this should happen each time when i add new object to that array list. Means execution time should be same (Little variation may happen).</p>
  
  <p>But when i add new record its shows 0 and some time 15.</p>
  
  <p>Here is my program</p>
  
  <pre><code>package com.rais;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class ArrayListTest {
  
      public static List&lt;String&gt; arrList = new ArrayList&lt;String&gt;();
      static {
          for (int i = 0; i &lt; 3000000; i++) {
              arrList.add("Hello"+i);
          }
      }
  
  
      public static void main(String[] args) {
          for (int i = 0; i &lt; 5; i++) {
  
              long startTime = System.currentTimeMillis();
  
              arrList.add(0,"Rais"+i);
  
              long endTime = System.currentTimeMillis();
              System.out.println("Total execution time ="+(endTime-startTime));
  
  
          }
         }
  
      }
  </code></pre>
  
  <p>And here is output of that program.</p>
  
  <pre><code>Total execution time =0
  Total execution time =0
  Total execution time =15
  Total execution time =0
  Total execution time =0
  </code></pre>
  
  <p>I am confused why it shows 0 . It should show 15 or little near to 15 each time but it should not show 0. </p>