Modify and return the given map as follows: if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the value "". Basically "b" is a bully, taking the value and replacing it with the empty string.

Check below code:

package com.test.collections;

import java.util.HashMap;
import java.util.Map;

public class MapBully 
{
	public static void main(String args[])
	{
		MapBully mb = new MapBully();
		HashMap<String, String> hm = new HashMap<String, String>();
		hm.put("a","candy");
		hm.put("b","dirt");
		System.out.println(mb.mapBully(hm));
	}

	public Map<String, String> mapBully(HashMap<String, String> map) 
	{
        if(map.containsKey("a"))
        {
        	map.put("b", map.get("a"));
        	map.put("a", "");
        }
        return map;
    }
}

Output

{a=, b=candy}