I'm using the following code for checking if a key exists in a Map
instance:
if (!map_instance.containsKey(key))
throw new RuntimeException("Specified key doesn't exist in map");
else
return map_instance.get(key);
My question is:
Is there a utility or Map
implementation to simplify the above code, such as:
custom_map.get(key,"Specified key doesn't exist in map");
My goal is: if key
does not exist in map, the map implementation throws an exception with the passed string.
I don't know whether or not my desire is reasonable?
(Sorry if I am using the wrong terminology or grammar, I am still learning the English language.)