title: java list java.util.ConcurrentModificationException
body: <p>I have this peace of code. <br>
  I know that this must give me ConcurrentModificationException <br>
  and i must use iterator or clone the list or just use for loop. <br></p>
  
  <p>The problem is that this code runs without problem and ls.remove works at any index between 0-2.<br>
  Now <strong>if</strong> i change <strong>s.equals("two")</strong> to <strong>s.equals("one")</strong> OR anything else from list except "two" <br>
  I will always get ConcurrentModificationException as expected. <br>
  <br>
  Also if i uncomment the ls.add("four") line ,i will always have ConcurrentModificationException no matter what the <strong>s.equals()</strong> be.<br>
  <br>
  <strong>And</strong> my questions is why this is happening and why the code below run fine whithout ConcurrentModificationException only for s.equals("two") ?</p>
  
  <pre><code>import java.util.*;
  import java.util.List;
  
      public class Test {
  
      public static void main(String args[]) {
  
          List&lt;String&gt; ls = new ArrayList&lt;&gt;();
  
          ls.add("one");
          ls.add("two");
          ls.add("three");
          //ls.add("four");
  
          for(String s : ls) {
              if(s.equals("two")) {
                  ls.remove(0);
                  //ls.remove("three");
              }
          }
  
          System.out.println(ls.size());
  
      }
  
  }
  </code></pre>
  
  <p><strong>and the output</strong></p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
  at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
  at java.util.ArrayList$Itr.next(ArrayList.java:851)
  at Test.main(Test.java:15)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.    java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
  </code></pre>