I've been having trouble really comprehending hashmaps from the start. I don't want to just copy code, that isn't how to learn. I've spent much longer on this than I would like, and no matter how many articles I've read on SO or in the JAVADOCS I'm just having a super hard time understanding the Iterator stuff, how to compare the values, and just generally basic Map manipulation. If anyone can explain some stuff, or point me to a well ELI5 article on how to do different stuff in hashmaps I would be very grateful.
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> nameMap = new HashMap<>();
nameMap.put("Cat", "Sylvester");
nameMap.put("Stallone", "Sylvester");
nameMap.put("Pig", "Porky");
nameMap.put("Clinton", "George");
nameMap.put("Bush", "George");
nameMap.put("Sandler", "Adam");
nameMap.put("Savage", "Adam");
nameMap.put("Einstien", "Alberto");
nameMap.put("Leon", "PonceDe");
nameMap.put("Bucks", "Star");
return nameMap;
}
public static void removeFirstNameDuplicates(Map<String, String> map) {
for (Map.Entry<String, String> pair : createMap().entrySet()
) {
String s = pair.getValue();
removeItemFromMapByValue(createMap(), s);
}
}
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) {
}
}