I'm calling the removeItemFromMapByValue method in my removeFirstNameDuplicates method but it's not working. I'm completely stumped on this. Your help is appreciated.
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import java.util.Set;
import java.util.*;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<String, String>();
map.put("a","one");
map.put("b","two");
map.put("c","three");
map.put("d","four");
map.put("e","five");
map.put("f","six");
map.put("g","seven");
map.put("h","eight");
map.put("i","nine");
map.put("j","ten");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
HashMap<String, String> duplicatMap = new HashMap<>();
Iterator<Map.Entry<String,String>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String,String> entry = iter.next();
String value = entry.getValue();
if(duplicatMap.containsKey(value)) {
//duplicatMap.remove(value);
removeItemFromMapByValue(map, value);
}
}
}
public static void removeItemFromMapByValue(Map<String, String> map, String value) {
HashMap<String, String> copy = new HashMap<String, String>(map);
for (Map.Entry<String, String> pair : copy.entrySet()) {
if (pair.getValue().equals(value))
map.remove(pair.getKey());
}
}
public static void main(String[] args) {
}
}