title: IndexOutOfBoundsException when adding to ArrayList at index
body: <p>I get exception <code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0</code> for the below code. But couldn't understand why.</p>
  
  <pre><code>public class App {
      public static void main(String[] args) {
          ArrayList&lt;String&gt; s = new ArrayList&lt;&gt;();
  
          //Set index deliberately as 1 (not zero)
          s.add(1,"Elephant");
  
          System.out.println(s.size());                
      }
  }
  </code></pre>
  
  <h1>Update</h1>
  
  <p>I can make it work, but I am trying to understand the concepts, so I changed declaration to below but didnt work either.</p>
  
  <pre><code>ArrayList&lt;String&gt; s = new ArrayList&lt;&gt;(10)
  </code></pre>