/*
Output:
Array of: int
Array size: 3
* */
import java.lang.reflect.Array;
public class MainClass {
public static void main (String args[]) {
Object array = Array.newInstance(int.class, 3);
Class type = array.getClass();
if (type.isArray()) {
Class elementType = type.getComponentType();
System.out.println("Array of: " + elementType);
System.out.println("Array size: " + Array.getLength(array));
}
}
}
|