I am comparing every entry in a HashMap
to every other entry in the same HashMap
. While iterating the HashMap
I remove some elements based on some conditions. However I keep getting the ConcurrentModificationException
.
Iterator<Entry<String, String>> i = map.entrySet().iterator();
while (i.hasNext()) {
Entry<String, String> next = i.next();
for (Entry<String,String> e : map.entrySet()) {
if (e.getKey() != next.getKey()){
String[] positions_e = fields_e[1].split("-");
int start_e = Integer.parseInt(positions_e[0]);
int end_e = Integer.parseInt(positions_e[1]);
String[] positions_next = fields_next[1].split("-");
int start_next = Integer.parseInt(positions_next[0]);
int end_next = Integer.parseInt(positions_next[1]);
if (start_e <= start_next || end_e <= end_next )) {
i.remove();
}
}
}