Java record-87-java. lang. reflect. Array
The java. lang. reflect. Array class provides various static methods for dynamically creating and accessing Array elements.
Import java. lang. reflect. Array; public class ArrayTester1 {public static void main (String [] args) throws Exception {Class <?> ClassType = Class. forName ("java. lang. string "); Object array = Array. newInstance (classType, 10); Array. set (array, 5, "hello"); String str = (String) Array. get (array, 5); System. out. println (str); // hello} public class ArrayTester2 {public static void main (String [] args) throws Exception {int [] dims = new int [] {5, 10, 15}; Object array = Array. newInstance (Integer. TYPE, dims); // generates a three-dimensional array with dimensions of 5, 10, and 15. // System. out. println (array instanceof int [] [] []); // true Object arrayobj = Array. get (array, 3); // obtain the third element of the first dimension, that is, a two-dimensional array // System. out. println (arrayobj instanceof int [] []); // true arrayobj = Array. get (arrayobj, 5); // get a one-dimensional Array. set (arrayobj, 10, 37); int [] [] [] arraycast = (int [] [] []) array; System. out. println (arraycast [3] [5] [10]); // System. out. println (Integer. TYPE); // int // System. out. println (Integer. class); // class java. lang. integer }}