No idea how to proceed. Can anybody point to some more background information in regards to calling one method in another method wile iterating over a HashMap?
I'm really stuck on this topic and even though I keep rereading the articles I can't find a way to solve these task. Really I actually do not know where to begin.
If someone can send me a link with a better explanation of these topics I would very much appreciate it.
I also hope that codegym will be better at explaining other complicated concepts because I'm rather disappointed at this moment and I'm making too little progress in the last few days. Other learners feel the same?
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<>();
map.put("LastName1", "Name1");//create a HashMap with 10 key-value pairs (lastName , name)
map.put("LastName2", "Name1");//changed the first letter to capitals
map.put("LastName3", "Name5");//changed the name of the HashMap from names to map
map.put("LastName4", "Name7");//still not working why?
map.put("LastName5", "Name9");// keys CANNOT be the same
map.put("LastName6", "Name10");//values can be the same but NOT the keys
map.put("LastName7", "Name11");
map.put("LastName8", "Name13");
map.put("LastName9", "Name14");
map.put("LastName10", "Name15");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//write your code here
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while(iterator.hasNext){
Map.Entry<String, String> pair = iterator.next();
if(pair.getValue.equals(value)){
removeItemFromMapByValue();// this method should call this method why??
}
}
}
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) {
}
}