Guys although I've solved the task I don't understand why the following solution doesn't work. I know I can't use a ' for loop ' to remove elements
but this seems to make sense ,but it doesn't work. Iv'e tried googling with no satisfactory answers. Why doesn't this work :
Iterator <Map.Entry<String,String>>iterator = map.entrySet().iterator();
while (iterator.hasNext()){
Map.Entry<String,String> pair = iterator.next();
String name = pair.getValue();
removeItemFromMapByValue(map,name);
}
Looking for some insight
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Shuy
12 March 2020, 09:00useful
Youre calling the removeItemFromMapByValue with all the values of the map, I cant see you checking for duplicates, basically deleting all entries of the map.
+1
Ntuthuko Xaba
12 March 2020, 12:32
Thank you that makes sense , I just looked at the removeItemFromMapByValue() method again ,and realised in the end it would delete every element in the map.
0