Here you can find the source of addIfNotNull(Collection
public static <T> Collection<T> addIfNotNull(Collection<T> coll, T value)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.Collection; public class Main { /**/*from ww w . j av a2 s .co m*/ * Adds a value to the collection if it's not null. Returns the collection * as a convenience for chained invocations. * * @since 1.0.11 */ public static <T> Collection<T> addIfNotNull(Collection<T> coll, T value) { return addIf(coll, value, value != null); } /** * Adds a value to the collection if the boolean expression is true. * Returns the collection as a convenience for chained invocations. * * @since 1.0.8 */ public static <T> Collection<T> addIf(Collection<T> coll, T value, boolean expr) { if (expr) coll.add(value); return coll; } }