In my computer it remove persons correctly for duplicates name...but on website it still show error message.?
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<String, String>();
map.put("1", "Dhruv");
map.put("2", "Aarav");
map.put("3", "Lisa");
map.put("4", "Rahul");
map.put("5", "Jay");
map.put("6", "Twinkle");
map.put("7", "Nitara");
map.put("8", "Akshay");
map.put("9", "Rima");
map.put("10", "Jasmine");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
int count = 0;
HashMap<String, String> copy = new HashMap<String, String>(map);
for(Map.Entry<String, String> pair : map.entrySet())
{
String first = pair.getValue();
for(Map.Entry<String, String> pair2 : copy.entrySet())
{
String f = pair2.getValue();
if(f.equals(first))
count++;
}
if(count>=2)
{
map.remove(pair.getValue());
removeItemFromMapByValue(map, first);
}
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) {
}
}