Java Collection Add addArrayToCollection(T[] array, Collection collection)

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

Description

Adds all array elements to the given collection of the same type.

License

Open Source License

Parameter

Parameter Description
T a parameter
array array
collection existing collection or null (to create a new ArrayList automatically)

Declaration

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

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.Collection;

public class Main {
    /**/*  w ww.j  av a2 s.c  o  m*/
     * Adds all array elements to the given collection of the same type.
     * 
     * @param <T>
     * @param array
     *            array
     * @param collection
     *            existing collection or null (to create a new {@link ArrayList}
     *            automatically)
     */
    public static <T> void addArrayToCollection(T[] array,
            Collection<T> collection) {
        if (collection == null) {
            collection = new ArrayList<T>();
        }
        for (T o : array) {
            collection.add(o);
        }
    }
}

Related

  1. addAllSafe(Collection collection1, Collection collection2)
  2. addAllUncontained(Collection col1, Collection col2)
  3. addAllUnique(final Collection collection, final Collection values)
  4. addArray(Collection col, T[] array)
  5. addArray(java.util.Collection v, T array[])
  6. addArrayToCollection(T[] array, Collection collection)
  7. addCheck(Collection c, Object o)
  8. addCollections(Collection... inCollections)
  9. addCondition(Collection conditions, String condition, double value)