title: ArrayList.remove is not working in a loop
body: <p>I have following code-</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class ArrayListExp{
      public static void main (String[] args){
  
          ArrayList&lt;String&gt; name = new ArrayList&lt;String&gt;();
  
          name.add("Chris");
          name.add("Lois");
          name.add("Meg");
          name.add("Meg");
          name.add("Brain");
          name.add("Peter");
          name.add("Stewie");
  
          System.out.println(name);
  
          for ( int i = 0;  i &lt; name.size(); i++){
              String oldName = name.get(i);
              if(oldName.equals("Meg"))
              {
                  name.remove(i);
              }
          }
  
          System.out.println(name);
      }
  }
  </code></pre>
  
  <p>But here it gives me output -</p>
  
  <pre><code>[Chris, Lois, Meg, Meg, Brain, Peter, Stewie]
  [Chris, Lois, Meg, Brain, Peter, Stewie]
  </code></pre>
  
  <p>I am not getting the point, why this is not removing <code>Meg</code> but I have tried with only one <code>Meg</code> in that case it is working. And I when I am adding few more <code>Meg</code> in last the one <code>Meg</code> is not removed from the <code>ArrayList</code>. Why?</p>