I'd like to do the following functionality:
if (!map.contains(key)) {
  map.put(key, val);
}
Update: Let's assume it's not HashMap so the map is implemented as a tree of some kind.
However note that it's a little inefficient, since if we get into the if we actually search the map twice. I'd actually like to do something like that:
map.put_if_new_key(key, val);
Any idea how to do it in Java?
 
     
     
     
     
     
     
    