public static void removeFirstNameDuplicates(Map<String, String> map) {
HashMap<String,String> copy = new HashMap<String, String>(map);
for (Map.Entry<String,String> pair : copy.entrySet()) {
String value = pair.getValue();
removeItemFromMapByValue(map,value);
}
}
I dont understand why this solution dont work ?What is wrong with this idea
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Skynet
7 March 2020, 09:41useful
GG is correct, you are deleting all entries basically.
You need to place the call to removeItemFromMapByValue(map,value); in a condition, which checks whether any of the values are the same.
Hint: there's a great frequency() method in the Collections package, which you can use for that.
+1
Guadalupe Gagnon
7 March 2020, 04:27useful
i didnt run this code but just looking at it it would seem that it would remove every single value from map. A complete fire sale. You will need to program in a check so that it only removes items when there is more than 1 of that item.
+1
Goran
8 March 2020, 12:37
yeah i get it now thank you for help :)
0