title: Retrieve Nth item from ArrayList gives IndexOutOfBoundsException even when index is in range?
body: <p>I have an ArrayList and I am trying to measure the time it takes to retrieve an item from the middle of my ArrayList.</p>
  
  <p>Here it is:</p>
  
  <pre><code>  List&lt;Car&gt; cars = new ArrayList&lt;Car&gt;();
  
      for (int i = 0; i &lt; 1000000; i++) {
          cars.add(new Car(null, i));
  </code></pre>
  
  <p>How would I retrieve item 500000?</p>
  
  <p>I tried creating a variable like int example = 500000, then put cars.get(example). But I just got errors:</p>
  
  <p>java.lang.IndexOutOfBoundsException: Index: 500000, Size: 1</p>
  
  <p>Here why am I getting an IndexOutOfBoundsException even when the index I requested &lt; total entries?</p>
  
  <p>Any help would be appreciated. Thanks.</p>