Java Map Put putIfNull(Map map, Object key, Object defaultValue)

Here you can find the source of putIfNull(Map map, Object key, Object defaultValue)

Description

put If Null

License

Open Source License

Declaration

@SuppressWarnings("all")
    public static void putIfNull(Map map, Object key, Object defaultValue) 

Method Source Code

//package com.java2s;

import java.util.Map;

public class Main {
    @SuppressWarnings("all")
    public static void putIfNull(Map map, Object key, Object defaultValue) {
        if (key == null)
            throw new IllegalArgumentException("key must be not null");
        if (map == null)
            throw new IllegalArgumentException("map must be not null");
        if (map.get(key) == null) {
            map.put(key, defaultValue);/*from   w w w . ja va  2  s  .c  o m*/
        }
    }
}

Related

  1. putIfNotExists(Map map, K key, V value)
  2. putIfNotNull(final Map map, final String name, final String value)
  3. putIfNotNull(Map map, K key, V value)
  4. putIfNotNull(Map> params, String key, T value)
  5. putIfNotNullAndTrue(Map map, String key, Boolean boolValue)
  6. putIfSet(Map config, String key, Object... values)
  7. putIntoMap(Map m, T[] keys, S[] values)
  8. putIntoMap(String key, Object value)
  9. putItem(Map map, Object key, Object value)