need a nudge in the right direction
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import java.util.ArrayList;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> m = new HashMap<String, String>();
m.put("jo", "la");
m.put("ji", "lo");
m.put("je", "le");
m.put("al", "lu");
m.put("as", "la");
m.put("an", "en");
m.put("ad", "on");
m.put("af", "se");
m.put("ar", "no");
m.put("er", "en");
return m;
}
public static void removeFirstNameDuplicates(HashMap<String, String> map) {
//write your code here
ArrayList<String> l = new ArrayList<String>();
Iterator <HashMap.Entry<String, String>> i = map.entrySet().iterator();
Iterator <HashMap.Entry<String, String>> j = map.entrySet().iterator();
while (i.hasNext()){
Map.Entry<String, String> set = i.next();
while (j.hasNext()){
Map.Entry<String, String> set2 = j.next();
if (set.equals(set2.getValue())){
l.add(set.getValue());
}
}
}
for (String x : l){
System.out.println(x);
removeItemFromMapByValue(map, x);
}
}
public static void removeItemFromMapByValue(HashMap<String, String> map, String value) {
HashMap<String, String> copy = new HashMap<String, String>(map);
for (HashMap.Entry<String, String> pair : copy.entrySet()) {
if (pair.getValue().equals(value))
map.remove(pair.getKey());
}
}
public static void main(String[] args) {
}
}