List of utility methods to do Map Put
V | putIfAbsent(Map 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. synchronized (map) { V existingValue = map.get(key); if (existingValue != null) { return existingValue; map.put(key, value); return null; |
V | putIfAbsent(Map Adds the specified item to a map if it does not already exist. if (!map.containsKey(key)) { map.put(key, value); return value; return map.get(key); |
boolean | putIfAbsent(Map put If Absent if (map.containsKey(key)) return false; map.put(key, val); return true; |
void | putIfAbsent(Map Adds the given key and value pair into the map if the map does not already contain a value for that key if (!map.containsKey(name)) {
map.put(name, value);
|
V | putIfAbsentGet(Map Puts the value into the map if the key is not present. V existing = map.get(key); if (existing != null) { return existing; map.put(key, value); return value; |
boolean | putIfNonNull(Map put If Non Null if (value == null) { return false; map.put(key, value); return true; |
void | putIfNotExist(Map put If Not Exist if (!map.containsKey(key)) {
map.put(key, value);
|
boolean | putIfNotExists(final K key, final V value, final Map Puts a value with a key into a map if the key is previously unset. if (!map.containsKey(key)) { map.put(key, value); return true; } else { return false; |
V | putIfNotExists(Map super K, ? super V> map, K key, V value) put If Not Exists if (!map.containsKey(key)) { map.put(key, value); return (V) map.get(key); |
void | putIfNotNull(final Map map, final String name, final String value) Utility for adding element to a map if not null: puts the value in the map if is not null, does nothing if it is null. if (value != null) {
map.put(name, value);
|