title: Adding elements stops for a while in huge ArrayList
body: <p>While I was debugging performance of program with huge calculating task I have discovered that most of time of adding elements to big ArrayList is being taken  by adding 1 element. Can anyone explain why such thing happens?</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class MainArr {
      ArrayList&lt;Integer&gt; normalList = new ArrayList&lt;Integer&gt;();
  
      public static void main(String[] args) {
          MainArr m = new MainArr();
          m.addElements();
      }
  
      public void addElements() {
          long startTime = System.currentTimeMillis();
          for (int j = 0; j &lt; 20000000; j++) {
              long addTime = System.currentTimeMillis();
              this.normalList.add(j);
              if (System.currentTimeMillis() - addTime &gt; 50) {
                  System.out.println("slow index-" + j + " - time:" + (System.currentTimeMillis() - addTime));
              }
          }
          System.out.println("End after:" + (System.currentTimeMillis() - startTime));
      }
  }
  </code></pre>
  
  <p>Output(always the same indexes and times):</p>
  
  <pre><code>slow index-4102267 - time:1184
  slow index-6758091 - time:1444
  slow index-12459620 - time:3124
  slow index-14738741 - time:166
  End after:6651
  </code></pre>