Here you can find the source of addToMapIfNotNull(Map
public static void addToMapIfNotNull(Map<String, Object> map, String key, Object value)
//package com.java2s; //License from project: LGPL import java.util.Map; public class Main { public static void addToMapIfNotNull(Map<String, Object> map, String key, Object value) { addToMapIfNotNull(map, key, value, ""); }/*from ww w .ja v a 2 s. co m*/ public static void addToMapIfNotNull(Map<String, Object> map, String key, Object value, String keyPrefix) { if (keyPrefix == null) keyPrefix = ""; if (key != null && value != null) map.put(keyPrefix + key, value); } }