Here you can find the source of addArrayToCollection(T[] array, Collection
Parameter | Description |
---|---|
T | a parameter |
array | array |
collection | existing collection or null (to create a new ArrayList automatically) |
public static <T> void addArrayToCollection(T[] array, Collection<T> collection)
//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); } } }