Any Hints?
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> hashMap = new HashMap<>();
for(int i = 0; i < 10; i++)
{
hashMap.put("A"+i, "B");
}
return hashMap;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
int count = 0;
int flag = 0;
Iterator<Map.Entry<String, String>> itr1 = map.entrySet().iterator();
while(itr1.hasNext())
{
String s1 = itr1.next().getValue();
Iterator<Map.Entry<String, String>> itr2 = map.entrySet().iterator();
while(itr1.hasNext())
{
String s2 = itr2.next().getValue();
if(s1.equals(s2))
{
count++;
}
if(count > 1)
{
removeItemFromMapByValue(map, s2);
flag = 1;
}
}
if(flag == 1)
{
removeItemFromMapByValue(map, s1);
}
flag = 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) {
}
}