Java Collection Add addIgnoreNull(Collection collection, T object)

Here you can find the source of addIgnoreNull(Collection collection, T object)

Description

From Apache commons-collection.

License

BSD License

Parameter

Parameter Description
collection the collection to add to, must not be null
object the object to add, if null it will not be added

Exception

Parameter Description
NullPointerException if the collection is null

Return

true if the collection changed

Declaration

private static <T> boolean addIgnoreNull(Collection<? super T> collection, T object) 

Method Source Code

//package com.java2s;
// Distributed under the OSI-approved BSD 3-Clause License.

import java.util.Collection;

public class Main {
    /**/*from   www  .j a  va  2  s.co m*/
     * From Apache commons-collection.
     * 
     * Adds an element to the collection unless the element is null.
     * 
     * @param collection the collection to add to, must not be null
     * @param object the object to add, if null it will not be added
     * @return true if the collection changed
     * @throws NullPointerException if the collection is null
     * @since Commons Collections 3.2
     */
    private static <T> boolean addIgnoreNull(Collection<? super T> collection, T object) {
        return (object == null ? false : collection.add(object));
    }
}

Related

  1. addIfNotNull(Collection c, Object element)
  2. addIfNotNull(Collection coll, T value)
  3. addIfNotNull(Collection listToAddTo, T itemToAddToList, Object objectToCheckIfNull)
  4. addIfNotNull(final Collection collection, final V value)
  5. addIgnoreNull(Collection collection, Object object)
  6. addIgnoreNull(final Collection collection, final T object)
  7. addInClauseToQuery(StringBuilder query, Collection l)
  8. addItem(Collection collection, Object item)
  9. addMatchingStrings(Collection availableProperties, String startWith, Collection strings)

  10. HOME | Copyright © www.java2s.com 2016