Can anyone help me? these tasks with iterator and maps are keeping me bussy...
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
HashMap<String, String> namen = new HashMap<>();
namen.put("thomas", "de zitter");
namen.put("thomasa", "de zittrer");
namen.put("thomasz", "de zirtter");
namen.put("thomase", "de ziztter");
namen.put("thomasr", "de zitter");
namen.put("thomast", "de zsitter");
namen.put("thomasy", "de zittser");
namen.put("thomasu", "de zigtter");
namen.put("thomasi", "de zistter");
namen.put("thomaso", "de zitter");
return namen;
//write your code here
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
HashMap<String, String> copy = new HashMap<>(map);
Iterator<Map.Entry<String, String>> map1 = copy.entrySet().iterator();
while ( map1.hasNext())
{
String value1 = map1.next().getValue();
Iterator<Map.Entry<String, String>> map2 = copy.entrySet().iterator();
while ( map2.hasNext()){
String value = map2.next().getValue();
if (value1.equals(value)&& !map1.next().getKey().equals(map2.next().getKey())){
removeItemFromMapByValue(map, value);
}
}
}
}
/*
HashMap<String, String> map2 = new HashMap<>(map);
Iterator<Map.Entry<String,String>> itrmap2 = map2.entrySet().iterator();
Iterator<Map.Entry<String,String>> newitr = map.entrySet().iterator();
while (newitr.hasNext()){
while (itrmap2.hasNext()){
String value = newitr.next().getValue();
if (newitr.next().equals(itrmap2.next())){removeItemFromMapByValue(map,value );
}
}
}}
Iterator<Map.Entry<String, String>> itr = map.entrySet().iterator();
while (itr.hasNext()){
removeItemFromMapByValue(map,map.get(itr.next()));
}
//write your code here
}*/
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) {
}
}