Can someone help or guide me?
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Iterator;
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("Tranberg", "Anita");
map.put("Tranberg1", "Anita");
map.put("Al-Saffar", "Anders");
map.put("Luiz", "Anders");
map.put("Tranberg2", "Allan");
map.put("Tranberg3", "Katrine");
map.put("Tranberg4", "Katrine");
map.put("Tranberg5", "Else");
map.put("Tranberg6", "Jens");
map.put("Sørensen", "Henrik");
return map;
}
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 firstName = pair.getValue();
int nameCount = 0;
Iterator<Map.Entry<String, String>> iterator = copy.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> pair2 = iterator.next();
if (pair2.getValue().equals(firstName))
nameCount++;
if (nameCount > 1) {
map.remove(pair2.getKey());
nameCount = 1;
}
}
}
}
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) {
removeFirstNameDuplicates(createMap());
}
}