
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> hashMap = new HashMap<> ( );
hashMap.put ( "Ram", "Anand" );
hashMap.put ( "Rama", "Abhishek" );
hashMap.put ( "A" , "Manvik");
hashMap.put ( "P" , "Lakshmi");
hashMap.put ( "Krish", "Manjula" );
hashMap.put ( "R", "Ramamurthy" );
hashMap.put ( "G", "Rangaiah" );
hashMap.put ( "Bhagya", "Dhanamma" );
hashMap.put ( "K", "Krishnappa" );
hashMap.put ( "Boodh", "Rangamma" );
return hashMap;
}
public static void removeFirstNameDuplicates( Map<String, String> map) {
//write your code here
Map<String ,String > mapCp = new HashMap<> ( );
Map<String ,String > mapCp1 = new HashMap<> ( );
mapCp.putAll ( map );
mapCp1.putAll ( map );
// System.out.println ("removeFirstNameDuplicates: "+mapCp );
for (Map.Entry<String, String> pair : mapCp.entrySet()) {
String value = pair.getValue ().toString();
if (pair.getValue ().equals("Ramamurthy"))
removeItemFromMapByValue ( mapCp1, value);
}
}
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) {
}
}