title: illegalStateException when using iterator.remove ()
body: <p>I have a problem with iterator remove which is causing IllegalStateException. The error is occurring in </p>
  
  <p><strong>depIterator.remove()</strong>
  I'm not sure why this is occurring. Any help would be appreciated.</p>
  
  <pre><code>List&lt;Dependency&gt; listofAllDependency = new ArrayList&lt;Dependency&gt;();
  
      while(!dependencyTable.isEmpty()){          
          //allValuesDependentsAreBuilt = false;
          Iterator&lt;Entry&lt;Dependency, List&lt;Dependency&gt;&gt;&gt; depIterator = dependencyTable.entrySet().iterator();
  
          while(depIterator.hasNext()){
              ArrayList&lt;String&gt; allValuesDependentsAreBuilt = new ArrayList&lt;String&gt;();
  
              Entry&lt;Dependency, List&lt;Dependency&gt;&gt; depEntry = depIterator.next();
  
  
              //If the key's values have no dependencies
              if(depEntry.getValue().size()==0){
                  //System.out.println(depEntry.getKey());
                  listofAllDependency.add(depEntry.getKey());
                  dependencyTable.remove(depEntry); 
                  depIterator.remove(); 
              }
  
              for(Dependency dep :depEntry.getValue()){
  
                  if(!dependencyTable.containsKey(dep)){
                      allValuesDependentsAreBuilt.add("true"); 
                  }else
                  {
                      allValuesDependentsAreBuilt.add("false"); 
                  }
              }
  
              if(!allValuesDependentsAreBuilt.contains("false")){ 
  
                  listofAllDependency.add(depEntry.getKey());
                  dependencyTable.remove(depEntry);
                  depIterator.remove();
              }
  
          }
      }
  </code></pre>