Java Collection Add addAll(Collection source, Collection target)

Here you can find the source of addAll(Collection source, Collection target)

Description

Adds all the elements in the source to target.

License

Open Source License

Parameter

Parameter Description
source the source collection
target the destination collection

Declaration

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void addAll(Collection source, Collection target) 

Method Source Code

//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);
        }
    }
}

Related

  1. addAll(C collection, T... elements)
  2. addAll(Collection collection, Iterator iterator)
  3. addAll(Collection collection, Object[] array)
  4. addAll(Collection collection, Object[] array)
  5. addAll(Collection ret, Object[] elements)
  6. addAll(Collection col, Iterable iterable)
  7. addAll(Collection collection, Iterable toAdd)
  8. addAll(Collection addTo, Iterable elementsToAdd)
  9. addAll(Collection c, Iterable elts)