Java Collection Add addIfNotNull(Collection listToAddTo, T itemToAddToList, Object objectToCheckIfNull)

Here you can find the source of addIfNotNull(Collection listToAddTo, T itemToAddToList, Object objectToCheckIfNull)

Description

Utility method to add an Object to a List if another passed Object is not null

License

Open Source License

Declaration

public static <T> void addIfNotNull(Collection<T> listToAddTo, T itemToAddToList, Object objectToCheckIfNull) 

Method Source Code

//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);
        }
    }
}

Related

  1. addIfMissing(Collection result, Iterable addition)
  2. addIfNotContains(Collection collection, T value)
  3. addIfNotEmpty(Collection c, Collection elements)
  4. addIfNotNull(Collection c, Object element)
  5. addIfNotNull(Collection coll, T value)
  6. addIfNotNull(final Collection collection, final V value)
  7. addIgnoreNull(Collection collection, Object object)
  8. addIgnoreNull(Collection collection, T object)
  9. addIgnoreNull(final Collection collection, final T object)