What is the problem?
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/*
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", "Name1");
Map.put("2", "Name3");
Map.put("3", "Name3");
Map.put("4", "Name6");
Map.put("5", "Name6");
Map.put("6", "Name4");
Map.put("7", "Name4");
Map.put("8", "Name6");
Map.put("9", "Name4");
Map.put("10", "Name99");
return Map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
HashMap<String, String> newMap = new HashMap<String, String>();
HashSet<String> set = new HashSet<String>();
newMap.putAll(map);
Iterator<Map.Entry<String, String>> newiterator = newMap.entrySet().iterator();
int i = 0;
while (newiterator.hasNext())
{
Map.Entry<String, String> newpair = newiterator.next();
i++;
int j = 0;
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext())
{
j++;
Map.Entry<String, String> pair = iterator.next();
if (i != j)
if (newpair.getValue().equals(pair.getValue()))
set.add(newpair.getValue());
}
}
for (String text : set)
{
removeItemFromMapByValue(map,text);
}
}
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> newMap = new HashMap<String, String>();
HashMap<String, String> map = new HashMap<String, String>();
HashSet<String> set = new HashSet<String>();
newMap.putAll(createMap());
map.putAll(createMap());
//Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
Iterator<Map.Entry<String, String>> newiterator = newMap.entrySet().iterator();
int i = 0;
while (newiterator.hasNext())
{
Map.Entry<String, String> newpair = newiterator.next();
i++;
int j = 0;
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext())
{
j++;
Map.Entry<String, String> pair = iterator.next();
//System.out.println("new: " + newpair.getValue());
//System.out.println("old: " + pair.getValue());
if (i != j)
if (newpair.getValue().equals(pair.getValue()))
set.add(newpair.getValue());
}
}
//set.add("akármi");
//System.out.println("text");
for (String text : set)
{
//System.out.println(text);
removeItemFromMapByValue(map,text);
}
for (Map.Entry<String, String> pair : map.entrySet())
{
String key = pair.getKey(); // Key
String value = pair.getValue(); // Value
System.out.println(key + ":" + value);
}
*/
}
}