title: Java ArrayList throws IndexOutOfBoundsException after removing items from the list
body: <p>When we create an ArrayList and check its size, it gives the value as 0. However, when we add an element and remove that element, and then check its size, it throws exception.</p>
  
  <p>What is the internal implementation in remove() method, that it changes the definition of an empty list?</p>
  
  <p>Code below gives output as 0.</p>
  
  <pre><code>List&lt;Integer&gt; list2 = new ArrayList&lt;Integer&gt;();
  System.out.println(list2.size());
  </code></pre>
  
  <p>Code below throws Exception:</p>
  
  <pre><code>List&lt;Integer&gt; list1 = new ArrayList&lt;Integer&gt;();
  list1.add(1);
  System.out.println(list1.size());
  list1.remove(1);
  System.out.println(list1.size());
  </code></pre>