title: Removing duplicates from arraylist
body: <pre><code>for (int i=0; i&lt;name.size(); i++)
  {
     for (int j = 1; j&lt;name.size(); j++)
        if (name.get(i).equals(name.get(j)))
        {
           name.remove(i);
           name.remove(j);
           j=j-1;
        }
  }
  </code></pre>
  
  <p>Initially, <code>name</code> is an <code>ArrayList</code> with 400 elements. I am trying to remove the duplicated elements. I don't know why my compiler keeps giving me </p>
  
  <blockquote>
    <p>java.lang.IndexOutOfBoundsException: Index: 1, Size: 1</p>
  </blockquote>
  
  <p>note that I am trying to remove the duplicated pair. There can only be two same element in the arraylist. 3 or more is not possible.</p>