package d18_4_2; import java.lang.reflect.Array; /** * 常用方法 * static Object newInstance(Class<?> componentType,int.. length) * 创建一个具有指定元素类型,指定维度的新数组 * * static xxx getXxx(Object array,int index) * 返回array数组中第index个元素 * * static void setXxx(Object array,int index,xxx val) * 将arr数组中第index个元素的值设为val * */ public class ArrayTest { public static void main(String[] args) { Object arr=Array.newInstance(String.class, 10); Array.set(arr,1,"spring"); Array.set(arr,2,"springMVC"); Array.set(arr,3,"mybatis"); System.out.println(Array.get(arr,0)); System.out.println(Array.get(arr,1)); System.out.println(Array.get(arr,2)); System.out.println(Array.get(arr,3)); } }