Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.Array; import java.util.Collection; public class Main { /** * Copies a collection into an array. * * @param collection * is the collection that should be copied to an array * @param type * is the class of the elements in the collection * @return the array copy */ public static <T> T[] toArray(final Collection<T> collection, final Class<T> type) { final int size = collection.size(); @SuppressWarnings("unchecked") final T[] array = (T[]) Array.newInstance(type, size); collection.toArray(array); return array; } }