I really don't think there is I might be wrong, but I don't think so. The Collection api specifies that the constructor of ArrayList (and it's associated siblings) take a Collection so you could give them another type of list and it would be happy, or anything else from the Collection group but not an array.
Follow the bouncing link.
http://java.sun.com/docs/books/tutorial/collections/index.html
Hope this helps,
PS.
You could write a fill method like the following, although I threw up in my mouth a little when I wrote this code...
import java.util.*;
public class Test {
public static void main(String[] args) {
List[] a = (List[]) fill(new ArrayList[5]);
for (int i = 0; i<a.length; ++i)
a[i].add("testing");
}
static Object[] fill(Object[] a) {
try {
Class cls = a.getClass().getComponentType();
for(int i = 0; i><a.length; ++i) {
a[i] = cls.newInstance();
}
} catch (Exception e) {
e.printStackTrace();
}
return a;
}
}
>
Thanks for your info and suggestions. It's a shame there's no easy way to do it... it narks me that I have to waste computational time iterating through a 3D array I have right now (for a particle system) just so that the elements are instantiated; I'm forced to do it like that, because the cunningly optimized force algorithms a friend and I have conjured up don't necessarily visit the nodes in an ordered fashion, and it would be more expensive to have a test for null every time I visit a 3D cell. Oh well.
Thank you again everyone.
> You could write a fill method like the following,
> although I threw up in my mouth a little when I wrote
> this code...
LOL! Neat example though, nonetheless :o)