title: java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
body: <p>Scenario:-</p>
  
  <p>I have two <code>ArrayList</code> </p>
  
  <p>list contains images </p>
  
  <p>postList contains position of  selected images</p>
  
  <p><strong>now when ever i am selecting the images and press delete menu ,it should delete the selected images .</strong></p>
  
  <p>when i am running the code in <code>debug</code> ,its working fine and give the desire output.</p>
  
  <p>but when i am running it normal mode ,its crashing and giving above <code>exception</code>.</p>
  
  <pre><code>if (posList.size() &gt; 0)
  {
      Toast.makeText(getBaseContext(), "i value" +posList.size(), 
                     Toast.LENGTH_SHORT).show();
      for (int i = 0; i &lt; posList.size(); i++)
          appAdp.list.remove(appAdp.list.get(posList.get(i)));
      appAdp.notifyDataSetChanged();
      posList.clear();
      Toast.makeText(getBaseContext(), "You deleted selected items",
                     Toast.LENGTH_SHORT).show();              
  }
  return true;
  </code></pre>
  
  <p>postList values here</p>
  
  <pre><code>@Override
          public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
                  boolean checked) {
              posList.add(position);
  </code></pre>
  
  <p>error showing here </p>
  
  <pre><code>appAdp.list.remove(appAdp.list.get(posList.get(i)));
  </code></pre>
  
  <p>logcat:-</p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
  
  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
  
  at java.util.ArrayList.get(ArrayList.java:304)
  </code></pre>
  
  <p>why its behaving like this ,not getting any clue.</p>
  
  <p>Thanks for any help.</p>