Не могу понять почему не проходит проверку. Благодарю заранее всех отозвавшихся
package com.javarush.task.task08.task0817;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
/*
Нам повторы не нужны
*/
public class Solution {
public static Map<String, String> createMap() {
//напишите тут ваш код
Map<String, String> stringMap = new IdentityHashMap<>();
stringMap.put("Bats", "Andrey");
stringMap.put("End", "Andrey");
stringMap.put("Little", "Andrey");
stringMap.put("Count", "Andrey");
stringMap.put("VEry", "Andrey");
stringMap.put("Well", "Andrey");
stringMap.put("Interesting", "Andrey");
stringMap.put("Game", "Andrey");
stringMap.put("Chitko", "Andrey");
stringMap.put("Go", "Andrey");
return stringMap;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
//напишите тут ваш код
HashSet<String> strings = new HashSet<>();
for (Map.Entry<String, String> pair : map.entrySet()) {
if (!strings.add(pair.getValue()))
removeItemFromMapByValue(map, pair.getValue());
}
// removeItemFromMapByValue(map, "Andrey");
// for (Map.Entry<String, String> pair : map.entrySet()) {
// System.out.println("Key: " + pair.getKey() + " Value: " + pair.getValue());
// }
}
public static void removeItemFromMapByValue(Map<String, String> map, String value) {
Map<String, String> copy = new HashMap<>(map);
for (Map.Entry<String, String> pair : copy.entrySet()) {
if (pair.getValue().equals(value)) {
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) {
Map<String, String> copy = createMap();
removeTheFirstNameDuplicates(copy);
}
}