Create new Array instance

static Object newInstance(Class<?> componentType, int... dimensions)
Creates a new array with the component type and dimensions.
static Object newInstance(Class<?> componentType, int length)
Creates a new array with the component type and length.

import java.lang.reflect.Array;

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

Create multidimensional array


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);
    
  }
}
Home 
  Java Book 
    Reflection  

Array:
  1. Array
  2. Get the length of an Array
  3. Get value from an Array
  4. Create new Array instance
  5. Set value to an Array