Java Reflection - Java Array.newInstance(Class <?> componentType, int... dimensions)








Syntax

Array.newInstance(Class <?> componentType, int... dimensions) has the following syntax.

public static Object newInstance(Class <?> componentType,   
                                             int... dimensions)    
                                 throws IllegalArgumentException ,     
                                        NegativeArraySizeException

Example

In the following code shows how to use Array.newInstance(Class <?> componentType, int... dimensions) method.

import java.lang.reflect.Array;

public class Main {
  public static void main(String[] argv) throws Exception {
    int[][] ints = (int[][]) Array.newInstance(int.class, 10,5);
    
  }
}