title: Relation between ConcurrentModificationException and
body: <p>I have created this list</p>
  
  <pre><code>List&lt;Integer&gt; first_solution = new ArrayList&lt;Integer&gt;();
  </code></pre>
  
  <p>and i have a previous list <code>randomPath</code> which is not empty</p>
  
  <p>My goal is to copy a part from <code>randomPath</code> into the new list <code>first_solution</code></p>
  
  <p>This is a part of my code</p>
  
  <pre><code>i = 2;
  
  if (distanceTraveled &gt; tMax &amp;&amp; !alreadyExecuted) {
              first_solution = randomPath.subList(0, i);
              displayPath(first_solution);
              alreadyExecuted = true;
      }
  </code></pre>
  
  <p>this code works without any problem perhaps when i use <code>first_solution</code> out of this function , i get this exception:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.util.ConcurrentModificationException</p>
  </blockquote>
  
  <p>For example if i want to write</p>
  
  <pre><code>displayPath(first_solution);
  </code></pre>
  
  <p>out of <code>if {}</code>, i get that exception.</p>