I have a loop to iterate a hashmap. If the condition is satisfied I need to remove the key, value pair from the hashmap. I am unable to do it using the below code. How can I achieve this?
for(HashMap.Entry<Integer,Character> m:commons.entrySet()){
while(i!=(int)m.getKey()){
i++;
}
if(s2.charAt(i)!=(int)m.getKey()){
commons.remove((int)m.getKey());
}
}