title: Unexpected IndexOutOfBoundException when getting value of an ArrayList
body: <pre><code>public static void main(String[] args) {
      List&lt;Integer&gt; values = new ArrayList&lt;&gt;(30);
      for (int i = 0; i &lt; values.size(); i++){
          values.add(i, 0);
      }
      int j = 0;
      int ghh = values.get(j);
  }
  </code></pre>
  
  <p>Above is a simple code snippet that gives an <code>OutOfBoundException</code> at the last line. Why is this exception being thrown? Do I actually need to use the for-loop for initiating <code>0</code> value of all the elements of the list?</p>