title: Java ArrayList<Double> IndexOutOfBoundsException Problem
body: <p>I've got a Problem with <code>ArrayList</code>. I need it to store a result. Because I want to start with element n I tried to give the <code>ArrayList</code> a capacity with <code>ensureCapacity(n+1)</code> to use <code>set(n,x)</code> but I get an <code>IndexOutOfBoundsException</code>. </p>
  
  <p>I tried to store n <code>add(x)</code> before the use of set and this works.</p>
  
  <p>So I'd like to know why it doesn't work on my way and how to solve this because put n times a <code>add(x)</code> isn't a good style ;-)</p>