Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 698 Bytes

mapShare.md

File metadata and controls

25 lines (19 loc) · 698 Bytes

mapShare

Modify and return the given map as follows: if the key "a" has a value, set the key "b" to have that same value. In all cases remove the key "c", leaving the rest of the map unchanged.

mapShare({"a": "aaa", "b": "bbb", "c": "ccc"}) → {"a": "aaa", "b": "aaa"}
mapShare({"b": "xyz", "c": "ccc"}) → {"b": "xyz"}
mapShare({"a": "aaa", "c": "meh", "d": "hi"}) → {"a": "aaa", "b": "aaa", "d": "hi"}

Solution:

public Map<String, String> mapShare(Map<String, String> map) {
  if(map.get("a") != null){
    map.put("b", map.get("a"));
  }
  map.remove("c");
  return map;
}

codingbat

< back to readme