I'm trying to iterate through a map and remove certain elements to construct a controlled vocabulary. Here is my code:
public static Map<String, Integer> controlVocab(Map<String, Integer> docf){
Set<String> set = docf.keySet();
Iterator<String> itr = set.iterator();
for (Map.Entry <String, Integer> entry : docf.entrySet())
{
if(entry.getValue()<50){
docf.remove(entry.getKey());
}
}
return docf;
}
But I keep getting this error: Exception in thread "main" java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429) at java.util.HashMap$EntryIterator.next(HashMap.java:1463) at java.util.HashMap$EntryIterator.next(HashMap.java:1461) at org.tartarus.snowball.TestApp.controlVocab(TestApp.java:114) at org.tartarus.snowball.TestApp.main(TestApp.java:619)
Does this make sense?