Hi, whats wrong with my code ? It doesn't pass verification ?
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> map = new HashMap<>();
map.put("Stallone", "Sylvester");
map.put("Stallone2", "Bruce");
map.put("Stallone3", "Arnold");
map.put("Schwarzenegger", "Sylvester");
map.put("Schwarzenegger2", "Bruce");
map.put("Schwarzenegger3", "Arnold");
map.put("Willis", "Sylvester");
map.put("Willis2", "Bruce");
map.put("Willis3", "Arnold");
map.put("Stallone4", "Sylvester4");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
int count = 0;
HashMap<String, String> map1 = new HashMap<>(map);
for (Map.Entry<String, String> x : map1.entrySet()) {
for (Map.Entry<String, String> y : map1.entrySet()) {
if (x.getValue().equals(y.getValue())){
count++;
if (count>1){
removeItemFromMapByValue(map,x.getKey());
count--;
}
}
}
count=0;
}
}
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) {
}
}