title: Use of the Iterator class in Java
body: <p>I am trying to use Iterator but it gives me this error:</p>
  
  <blockquote>
    <p>java.util.concurrentModificationException: null (in
    java.util.ArrayList$Itr)</p>
  </blockquote>
  
  <p>The code is here:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Iterator;
  
  public class Iteratorr
  {    
    ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
    Iterator&lt;String&gt; it = list.iterator();
  
    void add()
    {
      list.add("Hello");
      list.add("I");
      list.add("am");
      list.add("ArrayList");
    }
  
    void print()
    {   
      while(it.hasNext()) 
      {
        String str = it.next();
        System.out.println(str);
      }
    }      
  }
  </code></pre>
  
  <p>Can anyone explain the reason?</p>