Java Array.newInstance(Class <?> componentType, int length)

Syntax

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

public static Object newInstance(Class <?> componentType,   int length)    throws NegativeArraySizeException

Example

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


import java.lang.reflect.Array;
/*  w  ww.j a  v a2  s  . co m*/
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);
  }
}




















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable