Java LinkedList ConcurrentModificationException
<p>I wrote a simple code for LinkedList, to add data into it and iterate over it,<br/>
I imported the required packages for LinkedList and Iterator,
There is no error in the Code,<br/><br/>
<strong>I am getting the following Exception -</strong></p>

<pre><code>Exception in thread "main" java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(Unknown Source)
    at java.util.LinkedList$ListItr.next(Unknown Source)
    at collectionFramework.Demo.displayList(LinkedListDemo.java:38)
    at collectionFramework.LinkedListDemo.main(LinkedListDemo.java:13)
</code></pre>

<p><strong>Here's my code -</strong> </p>

<pre><code>package collectionFramework;

import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListDemo{

    public static void main(String[] args) {

        Demo obj = new Demo();

        obj.addToList();
        obj.displayList();
    }

}

class Demo{

    LinkedList&lt;String&gt; al;
    Iterator&lt;String&gt; itr;  

    Demo(){
        al = new LinkedList&lt;String&gt;();
        itr = al.iterator();
    }

    void addToList(){
          al.add("Aniruddha");  
          al.add("Hitesh");  
          al.add("Rahul");  
          al.add("Kshitij");  
    }

    void displayList(){

        while(itr.hasNext()){  
               System.out.println(itr.next());  
        }
    }
}
</code></pre>