Java List Null Empty addIgnoreNull(final List list, final T... objects)

Here you can find the source of addIgnoreNull(final List list, final T... objects)

Description

Adds the ignore null.

License

Open Source License

Parameter

Parameter Description
T the generic type
list the list
objects the objects

Return

the list

Declaration

public static <T> List<T> addIgnoreNull(final List<T> list, final T... objects) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import java.util.List;

public class Main {
    /**/*w ww .  j  av a  2  s.  c o m*/
     * Adds the ignore null.
     *
     * @param <T> the generic type
     * @param list the list
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> addIgnoreNull(final List<T> list, final T... objects) {
        if (objects == null)
            return list;
        for (final T object : objects)
            if (object != null)
                list.add(object);
        return list;
    }

    /**
     * Adds the.
     *
     * @param <T> the generic type
     * @param list the list
     * @param objects the objects
     * @return the list
     */
    public static <T> List<T> add(final List<T> list, final T... objects) {
        if (objects == null)
            return list;
        for (final T object : objects)
            list.add(object);
        return list;
    }
}

Related

  1. addAllExceptNullValue(List list, V[] values)
  2. addAllIfAllValuesNotNull(List list, V[] values)
  3. addIfNotNull(final List list, final T value)
  4. addIfNotNull(List l, T o)
  5. addIfValueNotNull(List list, V value)
  6. addListNotNullValue(List sourceList, V value)
  7. addNonEmpty(List list, String value)
  8. addNotNull(List list, T t)
  9. countIgnoreNull(List list)