|
The Array
class also has two newInstance()
methods that allow you to dynamically create an array of a
specified size and type:
- To create a single dimension array
public static Object newInstance(Class componentType,
int length)
throws NegativeArraySizeException
which does the equivalent of:
new componentType[length]
- To create a multiple dimension array
public static Object newInstance(Class componentType,
int[] dimensions)
throws IllegalArgumentException,
NegativeArraySizeException
which does the equivalent of
new componentType[dimensions[0]][dimensions[1]]...
|