Java List Value Add All addToList(List list, I item)

Here you can find the source of addToList(List list, I item)

Description

Convenience method to add an item to a list.

License

Open Source License

Parameter

Parameter Description
L Element type of list.
I Element type.
list List.
item Item to be added to the list. Will not be added if <code>null</code>.

Declaration

public static <L, I extends L> void addToList(List<L> list, I item) 

Method Source Code


//package com.java2s;
/*/*from w  w w .  j  a  va2 s . c  o m*/
 * OfficeFloor - http://www.officefloor.net
 * Copyright (C) 2005-2013 Daniel Sagenschneider
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.List;

public class Main {
    /**
     * Convenience method to add an item to a list. Will not add to list if
     * <code>null</code>.
     * 
     * @param <L>
     *            Element type of list.
     * @param <I>
     *            Element type.
     * @param list
     *            List.
     * @param item
     *            Item to be added to the list. Will not be added if
     *            <code>null</code>.
     */
    public static <L, I extends L> void addToList(List<L> list, I item) {
        if (item != null) {
            list.add(item);
        }
    }
}

Related

  1. addArrayToList(List list, double[] array)
  2. addArrayToList(List list, T[] array)
  3. addArrayToList(String[] array, List list)
  4. addArrayToList(T[] array, List list)
  5. addToList(List list, Object obj)
  6. AddToList(List tips, String tip)
  7. addToList(List dest, T src)
  8. addToList(List list, T value)
  9. addToList(List list, T[] array)