title: java.util.ArrayList$Itr.checkForComodification exception thrown
body: <p>when running the code below i get the above exception but i don't know why or how to fix it. 
  Im pretty sure it comes from </p>
  
  <pre><code>    for(int node : adjacent(currentnode))
          {
              //System.out.println(adjacent(currentnode));
              //System.out.println(node);
              if (remainingnodes.contains(getNode(node)))
              {
                  adjacent.add(node);
                  remainingnodes.remove(getNode(node));
                  //System.out.println(remainingnodes);
              }
          }
  </code></pre>
  
  <p>getNode just takes an integer and returns the corresponding node. I used to not get the exception before i used getNode in remainingnodes.contains but at the time it was removing the components so i had to change it and now i get the exception.</p>
  
  <pre><code>public int distance(int target, List&lt;Integer&gt; detectives)
  {
      List&lt;Integer&gt; adjacent = new ArrayList&lt;&gt;();
      Set&lt;Node&lt;Integer&gt;&gt; remainingnodes = new HashSet&lt;Node&lt;Integer&gt;&gt;();
      List&lt;Integer&gt; currentnodes = new ArrayList&lt;&gt;();
  
      int distance = 0;
      int i = 0;
  
  
  
      currentnodes.add(target);
      remainingnodes = graph.getNodes();
      remainingnodes.remove(getNode(target));
  
      while (detectives.size() != 0)
      {
  
          for (int currentnode : currentnodes)
          {
  
              for(int node : adjacent(currentnode))
              {
                  //System.out.println(adjacent(currentnode));
                  //System.out.println(node);
                  if (remainingnodes.contains(getNode(node)))
                  {
                      adjacent.add(node);
                      remainingnodes.remove(getNode(node));
                      //System.out.println(remainingnodes);
                  }
              }
              for (int detective : detectives)
              {
                  if (currentnode == detective)
                  {
                      distance = distance + i;
                      detectives.remove(detective);
                  }
              }
          }
  
      currentnodes.clear();
      currentnodes = adjacent;
      i++;
      }
  </code></pre>
  
  <p>Thanks 
  Arthur</p>