I feel like I hit a brick wall with this one. I'll need all the help i can get. My approach is to always understand exactly what's going on, even If I need to copy someone else's code.
First of all I need to understand what removeItemFromMapByValue is doing. Could someone help me understand that method? From what I understand I'm getting the Hashmap from (createMap) function, with a second argument. It's not quite clear to me what is the "String value" argument in:
removeItemFromMapByValue(Map<String, String> map, String value). What is it doing there? Where does it come from?
It is the same argument as seen in the census exercise: getSameLastNameCount(HashMap<String, String> map, String lastName). I could finish that exercise without fully comprehending it and now I don't want to bypass it again. And without understanding it I can't understand what the function is doing.
Thanks in advance, the community in this course is amazing.
Pablo
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() {
HashMap<String, String> map = new HashMap<String, String>();
map.put("firsst", "Raihn");
map.put("secdond", "Spahin");
map.put("thidrd", "Rffain");
map.put("fifrst", "Rjgain");
map.put("sfecond", "In");
map.put("th2ird", "Spaghin");
map.put("first", "Rghjyain");
map.put("second", "Ign");
map.put("third", "Spaddkln");
map.put("thirdasd", "gSpain");
return map;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
//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) {
}
}