Java tutorial
//package com.java2s; import java.util.Collection; public class Main { @SuppressWarnings("unchecked") public static <E> E[] asArray(final Collection<? extends E> collection) { return collection.toArray((E[]) new Object[collection.size()]); } @SuppressWarnings("unchecked") public static <E> E[] asArray(final Object... array) { final E[] elements = (E[]) new Object[array.length]; for (int i = 0; i < array.length; i++) { elements[i] = (E) array[i]; } return elements; } }