Created
January 26, 2012 16:56
-
-
Save gunith/1683766 to your computer and use it in GitHub Desktop.
Logic is, check for a value in the map... If it is there, get it. Otherwise, get a default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get a value from a {@link Map} or get a default value | |
* | |
* @param <K> Type of Key | |
* @param <V> Type of Value | |
* @param map The {@link Map} | |
* @param key The key in the {@link Map} | |
* @param defaultValue The default value for the key in the {@link Map} | |
* @return The value from {@link Map} | |
*/ | |
public static <K, V> V getValueFromMap(final Map<K, V> map, final K key, final V defaultValue) | |
{ | |
return map.containsKey(key) ? map.get(key) : defaultValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment