Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Array; import java.util.*; public class Main { public static Object[] toArrayOnListOfSameType(List aList) { if (aList.isEmpty()) return new Object[0]; Class type = aList.get(0).getClass(); Object[] sameElementsArray = (Object[]) Array.newInstance(type, aList.size()); return aList.toArray(sameElementsArray); } public static Object[] toArray(List aList, Class aType) { Object[] sameElementsArray = (Object[]) Array.newInstance(aType, aList.size()); return aList.toArray(sameElementsArray); } public static Object[] toArray(Iterator anIterator, Class eachElementType) { Vector vector = new Vector(); while (anIterator.hasNext()) vector.add(anIterator.next()); return toArray(vector, eachElementType); } }