I know that i wrote a spaghetti code but, i didn't understand how to resolve.
Thanks for help.
package com.codegym.task.task08.task0817;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String,String> ana = new HashMap<>();
ana.put("pi","po");
ana.put("ci","po");
ana.put("li","po");
ana.put("ri","so");
ana.put("ghi","po");
ana.put("pri","pro");
ana.put("pti","pto");
ana.put("pqi","pqo");
ana.put("pdfi","posf");
ana.put("pwei","prwero");
return ana;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
ArrayList<String> valueas = new ArrayList<>();
ArrayList<String>duplicates = new ArrayList<>();
for (Map.Entry<String,String> val:map.entrySet()
) {
valueas.add(val.getValue());
}
for (int i = 0; i <valueas.size();) {
for (int j = i+1; j <valueas.size()-1; j++) {
if(valueas.get(i).equals(valueas.get(j))){duplicates.add(valueas.get(i));}
}
i++;
}
for (Map.Entry<String,String> map2:map.entrySet()
) {
if(duplicates.contains(map2.getValue())){
map.remove(map2.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) {
}
}