title: How to remove multiple mappings in hashmap without ConcurrentModificationException?
body: <p>I have 2 hashmaps: <code>HashMap&lt;String, Word&gt; hmSmall, hmBig</code>. The mapping in each is <strong>many-to-one</strong>. Hence based on some criteria, I have to remove all the mappings corresponding to a particular value in both hashmaps. And for that, I am following <a href="https://stackoverflow.com/a/30214164/848377">this</a> answer. </p>
  
  <p>The problem is that I still get <code>ConcurrentModificationException</code> while iterating over the hashmap. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>for (Iterator&lt;Word&gt; it = hmSmall.values().iterator(); it.hasNext(); i++) {
              Word value = it.next();//java.util.ConcurrentModificationException here
              String key = value.getKey();
              if (hmBig.containsKey(key)) {
                  // if big contains less then remove from big
                  // else it.remove
  
                  if (hmBig.get(key).getTotalOccurances() &lt; value
                          .getTotalOccurances()) {
  
                      hmBig.values().removeAll(
                              Collections.singleton(hmBig.get(key)));
  
                  } else {
  
                      // it.remove(); not using this based on https://stackoverflow.com/a/30214164/848377
                      hmSmall.values().removeAll(Collections.singleton(value));
  
                  }
  
              }
          }
  </code></pre>
  
  <p>Is there simple way out?</p>