Код проверил в идее без плагина , все работает как надо ,но валидацию по предпоследнему пункту не проходит(((((
package com.javarush.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
/*
Нам повторы не нужны
*/
public class Solution {
public static Map<String, String> createMap() {
HashMap<String, String > map = new HashMap<String, String>();
map.put("Фамилия0", "Имя0");
map.put("Фамилия1", "Имя1");
map.put("Фамилия2", "Имя1");
map.put("Фамилия3", "Имя1");
map.put("Фамилия4", "Имя2");
map.put("Фамилия5", "Имя3");
map.put("Фамилия6", "Имя4");
map.put("Фамилия7", "Имя5");
map.put("Фамилия8", "Имя6");
map.put("Фамилия9", "Имя7");
return map;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
ArrayList<String> list = new ArrayList();
for (Map.Entry<String, String> pair : map.entrySet()){
list.add(pair.getValue());
}
String s = "o";
for (int i = 1; i < list.size(); i++){
if (list.get(i-1).equals(list.get(i))){
s = list.get(i);
}
}
removeItemFromMapByValue( map, s);
//напишите тут ваш код
// System.out.println(map);
}
public static void removeItemFromMapByValue(Map<String, String> map, String value) {
Map<String, String> copy = new HashMap<>(map);
for (Map.Entry<String, String> pair : copy.entrySet()) {
if (pair.getValue().equals(value)) {
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) {
//removeTheFirstNameDuplicates(createMap());
}
}