Java tutorial
//package com.java2s; import java.lang.reflect.Array; import java.util.*; public class Main { @SuppressWarnings("unchecked") public static <T> T[] collectionToArray(Collection<T> sourceCollection, Class<?> elementClass) { Object array = Array.newInstance(elementClass, sourceCollection.size()); Iterator iterator = sourceCollection.iterator(); for (int i = 0; i < sourceCollection.size(); i++) { Array.set(array, i, iterator.next()); } return (T[]) array; } }