Java Map Put putIfNotNull(Map> params, String key, T value)

Here you can find the source of putIfNotNull(Map> params, String key, T value)

Description

put value in map only if not null

License

LGPL

Parameter

Parameter Description
params a parameter
key a parameter
value a parameter

Declaration

public static <T> void putIfNotNull(Map<String, Collection<String>> params, String key, T value) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class Main {
    /**/*w  w  w .  j  a va  2  s . co  m*/
     * put value in map only if not null
     * 
     * @param params
     * @param key
     * @param value
     */
    public static <T> void putIfNotNull(Map<String, Collection<String>> params, String key, T value) {
        if (value != null) {
            params.put(key, Collections.singleton(String.valueOf(value)));
        }
    }
}

Related

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