Not passing the 4th task
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() {
//write your code here
HashMap<String,String> map = new HashMap<>();
map.put("1", "Harry");
map.put("2", "Sara");
map.put("3", "Sara");
map.put("4", "Karrt");
map.put("5", "Tim");
map.put("6", "Kim");
map.put("7", "Terry");
map.put("8", "Tell");
map.put("9", "Mary");
map.put("10", "Pat");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
HashMap<String, String> temp = new HashMap<String, String>(map);
int count = 0, no = 0;
for (Map.Entry<String, String> t : temp.entrySet()) {
String s0 = t.getValue();
for (Map.Entry<String, String> s : temp.entrySet())
{
//System.out.println(s0);
String s1 = s.getValue();
if (s0.equals(s1))
{
count++;
}
if(count > 1)
{
removeItemFromMapByValue(map,s1);
no = 1;
count = 1;
}
if (no == 1)
{
removeItemFromMapByValue(map,s0);
}
no = 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) {
HashMap<String,String> map = new HashMap<>();
map = createMap();
}
}