title: java.util.ConcurrentModificationException while inserting in ArrayList
body: <pre><code>import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.ListIterator;
  
  public class MyList {
      public static void main(String[] args) {
          ArrayList&lt;String&gt; al = new ArrayList&lt;String&gt;();
  
          al.add("S1");
          al.add("S2");
          al.add("S3");
          al.add("S4");
  
          Iterator&lt;String&gt; lir = al.iterator();
  
          while (lir.hasNext()) {
              System.out.println(lir.next());
          }
  
          al.add(2, "inserted");
  
          while (lir.hasNext()) {
             System.out.println(lir.next());
          }
      }
  }
  </code></pre>
  
  <p>The particular piece of code throws an error:</p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
      at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
      at java.util.ArrayList$Itr.next(Unknown Source)
      at collections.MyList.main(MyList.java:32)
  </code></pre>