Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.Collection; public class Main { /** * 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; } }