package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<String,String>();
map.put("Victor", "Omoha");
map.put("Vic", "Eze");
map.put("Jack", "Ma");
map.put("Wine", "Hude");
map.put("Larry", "Gaga");
map.put("Maggy", "Spoon");
map.put("Murry", "Oche");
map.put("Harry", "Manny");
map.put("Uche", "Jerry");
map.put("Sam", "Tom");
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()){
HashMap.Entry<String, String> pair = iterator.next();
if(pair.getKey().equals(map))
iterator.remove();
}
}
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) {
}
}
package com.codegym.task.task08.task0817;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/*
We don't need repeats
*/
public class Solution {
public static HashMap<String, String> createMap() {
//write your code here
HashMap<String, String> map = new HashMap<String,String>();
map.put("Victor", "Omoha");
map.put("Vic", "Eze");
map.put("Jack", "Ma");
map.put("Wine", "Hude");
map.put("Larry", "Gaga");
map.put("Maggy", "Spoon");
map.put("Murry", "Oche");
map.put("Harry", "Manny");
map.put("Uche", "Jerry");
map.put("Sam", "Tom");
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()){
HashMap.Entry<String, String> pair = iterator.next();
if(pair.getKey().equals(map))
iterator.remove();
}
}
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) {
}
}