Here you can find the source of addAll(Collection source, Collection target)
Parameter | Description |
---|---|
source | the source collection |
target | the destination collection |
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void addAll(Collection source, Collection target)
//package com.java2s; /*//from w ww . ja v a 2s . c om * Copyright (c) 2012 - Batoo Software ve Consultancy Ltd. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * 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 Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import java.util.Collection; import java.util.List; public class Main { /** * Adds all the elements in the source to target. * * @param source * the source collection * @param target * the destination collection * * @since $version * @author hceylan */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static void addAll(Collection source, Collection target) { if (source instanceof List) { final List<?> list = (List<?>) source; for (int i = 0; i < list.size(); i++) { target.add(list.get(i)); } } else { target.addAll(source); } } }