Here you can find the source of addToList(List
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>. |
public static <L, I extends L> void addToList(List<L> list, I item)
//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); } } }