1.动态创建数组
1 package com.classobject;
2 import java.lang.reflect.Array;
3 /**
4 * 动态创建数组和访问数组
5 */
6 public class ArrayNewInstanceTest {
7 public static void main(String[] args) {
8 //1.动态创建长度为10的String类型的数组
9 Object arr=Array.newInstance(String.
class, 10
);
10
11 //2.为arr数组索引为1位置赋值
12 Array.set(arr, 1, "holly"
);
13
14 //3.获取arr数组索引为1位置的值
15 Object o=Array.get(arr, 1
);
16
17 //4.打印获取的值
18 System.out.println(o);
19 }
20 }
转载于:https://www.cnblogs.com/holly8/p/5715314.html