title: NoSuchElementException occurs when Iterating through Java ArrayList concurrently
body: <p>I have a method similar to the one below:</p>
  
  <pre><code>public void addSubjectsToCategory() {
      final List&lt;Subject&gt; subjectsList = new ArrayList&lt;&gt;(getSubjectList());
      for (final Iterator&lt;Subject&gt; subjectIterator =
              subjectsList.iterator(); subjectIterator.hasNext();) {
           addToCategory(subjectIterator.next().getId());
      } 
  }
  </code></pre>
  
  <p>When this runs concurrently for the same user (another instance), sometimes it throws <code>NoSuchElementException</code>. As per my understanding, sometimes <code>subjectIterator.next()</code> get executed when there are no elements in the list. This occurs when being accessed only. Will method synchronization solve this issue?</p>
  
  <p>The stack trace is:</p>
  
  <pre><code>java.util.NoSuchElementException: null
  at java.util.ArrayList$Itr.next(Unknown Source)
  at org.cmos.student.subject.category.CategoryManager.addSubjectsToCategory(CategoryManager.java:221)
  </code></pre>
  
  <p>This stack trace fails at the <code>addToCategory(subjectIterator.next().getId());</code> line.</p>