Page 1 of 1

Arrays

Posted: Tue Feb 14, 2012 11:47 am
by adrianc
Hello i need to know if there is a way to convert from a generic data structure (say List<T>, Vector<T>, etc) to an array of T, because the method .toArray() returns an Object[]... and i need a T[]...
any words???

Re: Arrays

Posted: Fri May 11, 2012 1:41 am
by gmo
try this:
Object[] array = (Object[]) arrayList.toArray(new Object[0]);

i.e for int's
Integer[] a = (Integer[]) arrayList.toArray(new Integer[0]);

you have to use class name instead of data type. works for custom classes too. :D