title: Insert at any position in java.util.List
body: <p>According to the docs you can insert objects an any position in a List:</p>
  
  <blockquote>
    <p>The user of this interface has precise control over where in the list each element is inserted.</p>
  </blockquote>
  
  <p>(source: <a href="http://download.oracle.com/javase/6/docs/api/java/util/List.html">http://download.oracle.com/javase/6/docs/api/java/util/List.html</a>)</p>
  
  <p>But the following program fails with an IndexOutOfBoundsException:</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Test {
      public static void main(String[] args) {
          ArrayList&lt;String&gt; myList = new ArrayList&lt;String&gt;();
          myList.add(0, "derp");
          myList.add(2, "herp");
  
          for (String s : myList) {
              System.out.println("Le string: " + s);
          }
      }
  }
  </code></pre>
  
  <p>It doesn't help setting initial capacity explicitly, either (which makes some sense since the default value is 10).</p>
  
  <p>Why can't I insert objects at any position as long as its index is lower than the capacity? Is the size always equal to the number of inserted elements?</p>