Java Utililty Methods Map Put

List of utility methods to do Map Put

Description

The list of methods to do Map Put are organized into topic(s).

Method

VputIfAbsent(Map 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.
synchronized (map) {
    V existingValue = map.get(key);
    if (existingValue != null) {
        return existingValue;
    map.put(key, value);
    return null;
VputIfAbsent(Map map, K key, V value)
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);
booleanputIfAbsent(Map map, S key, T val)
put If Absent
if (map.containsKey(key))
    return false;
map.put(key, val);
return true;
voidputIfAbsent(Map map, String name, String value)
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);
VputIfAbsentGet(Map map, K key, V value)
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;
booleanputIfNonNull(Map map, K key, V value)
put If Non Null
if (value == null) {
    return false;
map.put(key, value);
return true;
voidputIfNotExist(Map map, K key, V value)
put If Not Exist
if (!map.containsKey(key)) {
    map.put(key, value);
booleanputIfNotExists(final K key, final V value, final Map 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;
VputIfNotExists(Map map, K key, V value)
put If Not Exists
if (!map.containsKey(key)) {
    map.put(key, value);
return (V) map.get(key);
voidputIfNotNull(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);