Java Map Put putIfNotNull(final Map map, final String name, final String value)

Here you can find the source of putIfNotNull(final Map map, final String name, final String value)

Description

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.

License

Open Source License

Parameter

Parameter Description
map the map to put in
name the key to use
value the value to add to the map

Declaration

public static void putIfNotNull(final Map map, final String name, final String value) 

Method Source Code


//package com.java2s;
// Released under the Canoo Webtest license.

import java.util.Map;

public class Main {
    /**/*from w w  w .j  a  va  2s .  c  om*/
     * 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.
     * 
     * @param map the map to put in
     * @param name the key to use
     * @param value the value to add to the map
     */
    public static void putIfNotNull(final Map map, final String name, final String value) {
        if (value != null) {
            map.put(name, value);
        }
    }
}

Related

  1. putIfAbsentGet(Map map, K key, V value)
  2. putIfNonNull(Map map, K key, V value)
  3. putIfNotExist(Map map, K key, V value)
  4. putIfNotExists(final K key, final V value, final Map map)
  5. putIfNotExists(Map map, K key, V value)
  6. putIfNotNull(Map map, K key, V value)
  7. putIfNotNull(Map> params, String key, T value)
  8. putIfNotNullAndTrue(Map map, String key, Boolean boolValue)
  9. putIfNull(Map map, Object key, Object defaultValue)