i have the following code:
public List<String> processMap(Map<String, String> aMap) {
Cloner cloner = new Cloner();
Map<String, String> tempMap = cloner.deepClone(aMap);
while(!tempMap.isEmpty()) {
Iterator<Entry<String, String>> iterator = tempMap.entrySet().iterator();
while(iterator.hasNext()) {
Entry<String, String> entry = iterator.next(); // !!!
}
}
return null;
}
To deep copy the map i use this library: Cloner
I marked the line where i unfortunately get a ava.util.ConcurrentModificationException with '!!!'
Can you please tell me why i get this exception?
The complete code:
Cloner cloner = new Cloner();
Map<String, FreebaseType> tempFreebaseTypes = new HashMap<String, FreebaseType>();
Map<String, FreebaseType> freebaseTypesCopy = cloner.deepClone(freebaseTypes);
while(!freebaseTypesCopy.isEmpty()) {
Iterator<Entry<String, FreebaseType>> iterator = freebaseTypesCopy.entrySet().iterator();
while(iterator.hasNext()) {
Entry<String, FreebaseType> entry = iterator.next();
if(tempFreebaseTypes.containsKey(entry.getValue().getSuperType()) || entry.getValue().getSuperType() == null) {
tempFreebaseTypes.put(entry.getValue().getType(), entry.getValue());
freebaseTypesCopy.remove(entry.getKey());
}
}
}
List<FreebaseType> sortedFreebaseTypes = new ArrayList<FreebaseType>();
Iterator<Entry<String, FreebaseType>> iterator = tempFreebaseTypes.entrySet().iterator();
while(iterator.hasNext()) {
Entry<String, FreebaseType> entry = iterator.next();
sortedFreebaseTypes.add(entry.getValue());
}
return sortedFreebaseTypes;
<String, String>why do you use an external library anyway? You can copy the content of one map into another withnewMap.putAll(originalMap)