Java tutorial
//package com.java2s; import java.lang.reflect.Array; import java.util.Collection; public class Main { @SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> c) { if (c == null) { return null; } else { T[] result = (T[]) Array.newInstance(c.getClass().getComponentType(), c.size()); int i = 0; for (T r : c) { result[i] = r; i++; } return result; } } }