Java Array to Collection arrayToCollection(E[] array, C collection)

Here you can find the source of arrayToCollection(E[] array, C collection)

Description

Constructs a new java.util.Collection that will contain the given array elements.

License

Open Source License

Parameter

Parameter Description
E a parameter
C a parameter
array a parameter
collection a parameter

Declaration

public static <E, C extends Collection<E>> C arrayToCollection(E[] array, C collection) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**//  w  ww .j av  a2s.  c  om
     * Constructs a new java.util.Collection that will contain the given array elements.
     * 
     * @param <E>
     * @param <C>
     * @param array
     * @param collection
     * @return
     */
    public static <E, C extends Collection<E>> C arrayToCollection(E[] array, C collection) {
        collection.clear();
        for (E e : array) {
            collection.add(e);
        }
        return collection;
    }
}

Related

  1. arrayToCollection(Collection collection, T[] elements)
  2. arrayToCollection(Object[] objs)
  3. arrayToCollection(String[] values)