Where did I go wrong?
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
/*
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("Tyrone","Botha");
map.put("Victoria","Botha");
map.put("John","Doe");
map.put("Rick","McDonald");
map.put("Casper","McDonald");
map.put("Mom","Taylor");
map.put("Carol","Botha");
map.put("Tom","McDonald");
map.put("Albert","Masingi");
map.put("Liam","Young");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
Map<String, String> duplicates = new HashMap<String, String>();
while(iterator.hasNext()){
Map.Entry<String, String> pair = iterator.next();
if(duplicates.containsValue(pair.getValue())){
removeItemFromMapByValue(map,pair.getValue());
removeItemFromMapByValue(map,pair.getValue());
removeItemFromMapByValue(map,pair.getValue());
}else{
duplicates.put(pair.getKey(),pair.getValue());
}
}
}
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) {
}
}