Return to Snippet

Revision: 48700
at July 7, 2011 21:33 by arunpjohny


Initial Code
public static <T> T[] convertToArray(List<T> values, Class<T> clazz) {
		Object object = Array.newInstance(clazz, values.size());
		for (int i = 0; i < values.size(); i++) {
			Array.set(object, i, values.get(i));
		}

		@SuppressWarnings("unchecked")
		T[] array = (T[]) object;
		return array;
	}

Initial URL
http://download.oracle.com/javase/tutorial/reflect/special/arrayInstance.html

Initial Description

                                

Initial Title
Converting a list into an array

Initial Tags
java

Initial Language
Java