How is the problem solved?
The removeFirstNameDuplicates() method must remove from the map all people who have the same first name.
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> hashMap = new HashMap<>();
for(int i = 0; i < 10; i++)
{
hashMap.put("A"+i, "B");
}
return hashMap;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
HashMap<String, String> Copy = new HashMap<>(map);
for (Map.Entry<String, String> pair : Copy.entrySet()
) {
removeItemFromMapByValue(Copy, 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) throws Exception {
}
}