public class MapUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <K,V> List<V> |
createNewListIfAbsent(Map<K,List<V>> map,
K key)
If the specified key is not already associated with a value (or is mapped
to null) associates it with a new List and returns it, else returns the
current value.
|
static <K,V> V |
getOrDefault(Map<K,V> map,
K key,
V defaultValue)
Returns the value to which the specified key is mapped, or defaultValue
if this map contains no mapping for the key.
|
static <K,V> V |
putIfAbsent(Map<K,V> map,
K key,
V value)
If the specified key is not already associated with a value (or is mapped
to null) associates it with the given value and returns null, else
returns the current value.
|
public static <K,V> V getOrDefault(Map<K,V> map, K key, V defaultValue)
K - The map key typeV - The map value typemap - the map to usekey - the key whose associated value is to be returneddefaultValue - the default mapping of the keypublic static <K,V> V putIfAbsent(Map<K,V> map, K key, V value)
K - The map key typeV - The map value typemap - the map to usekey - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic static <K,V> List<V> createNewListIfAbsent(Map<K,List<V>> map, K key)
K - The map key typeV - The map value type in the listmap - the map to usekey - key with which the specified value is to be associatedCopyright © 2010–2017 oshi. All rights reserved.