package com.javarush.task.task08.task0817; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /* Нам повторы не нужны */ public class Solution { public static HashMap<String, String> createMap() { HashMap<String, String> map = new HashMap<String, String>(); map.put("ugkjk", "tfgdtytdyd"); map.put("ugkdsf", "tfytsdyd"); map.put("ugkjksf", "tfyadwtdyd"); map.put("ugkjksfg", "tfytadwdyd"); map.put("ugkjkhty", "tfytdyfsed"); map.put("ugkjkt", "tfytdeyd"); map.put("ugkjkgd", "tfesytdyd"); map.put("ugerdfkjk", "tsfefytdyd"); map.put("ugkwejk", "tfytdysfd"); map.put("ugkjkwfe", "tfytdydrgd"); return map; } public static void removeTheFirstNameDuplicates(Map<String, String> map) { Iterator<Map.Entry<String, String>> iterator1 = map.entrySet().iterator(); while (iterator1.hasNext()){ int count=0; Iterator<Map.Entry<String, String>> iterator2 = map.entrySet().iterator(); Map.Entry<String, String> pair1 = iterator1.next(); while (iterator2.hasNext()) { Map.Entry<String, String> pair2 = iterator2.next(); if (pair1.getValue().equals(pair2.getValue())) count++; } if (count>=1) removeItemFromMapByValue(map, pair1.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) { } }