Here you can find the source of addIfNotNull(Collection
public static <T> void addIfNotNull(Collection<T> listToAddTo, T itemToAddToList, Object objectToCheckIfNull)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**// w ww . j a v a 2s . co m * Utility method to add an Object to a List if another passed Object is not null */ public static <T> void addIfNotNull(Collection<T> listToAddTo, T itemToAddToList, Object objectToCheckIfNull) { if (objectToCheckIfNull != null) { listToAddTo.add(itemToAddToList); } } }