Java Collection Merge mergeArrayIntoCollection(T[] array, Collection collection)

Here you can find the source of mergeArrayIntoCollection(T[] array, Collection collection)

Description

Merge the given array into the given Collection.

License

Open Source License

Parameter

Parameter Description
T type of elements of array
array the array to merge (may be <code>null</code>)
collection the target Collection to merge the array into

Declaration

public static <T> void mergeArrayIntoCollection(T[] array, Collection<T> collection) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008, 2010 VMware Inc.//  w w w.ja v  a  2s.co m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   VMware Inc. - initial contribution
 *******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * Merge the given array into the given Collection.
     * @param <T> type of elements of array
     * @param array the array to merge (may be <code>null</code>)
     * @param collection the target Collection to merge the array into
     */
    public static <T> void mergeArrayIntoCollection(T[] array, Collection<T> collection) {
        if (collection == null) {
            throw new IllegalArgumentException("Collection must not be null");
        }
        for (int i = 0; i < array.length; i++) {
            collection.add(array[i]);
        }
    }
}

Related

  1. merge(Collection... collections)
  2. merge(Collection... collections)
  3. merge(Collection... elems)
  4. merge(final Collection values)
  5. merge(J just, Collection justs)
  6. mergeCollection( final Collection col1, final Collection col2)
  7. mergeCollection(Collection a, Collection b)
  8. mergeCollections(Collection... inCollections)