首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

反照-整型数组

2014-01-25 
反射-整型数组package com.reflectimport java.lang.reflect.Array/** ** @Description:创建了一个 5 x

反射-整型数组

package com.reflect;import java.lang.reflect.Array;/** *  * @Description:   创建了一个 5 x 10 x 15 的整型数组(5个数组,每个数组10行15列数据), * 并把索引位置为[3][5][10] 的元素的值为设37   */public class ArrayTester2 {public static void main(String[] args) {int[] dims = new int[]{5,10,15};//创建一个具有指定的组件类型和维度的新数组。Object array = Array.newInstance(Integer.TYPE, dims);//获得第3个数组Object arrayObj = Array.get(array, 3);Class<?> cls = arrayObj.getClass().getComponentType();System.out.println(cls);//获得第5行arrayObj = Array.get(arrayObj, 5);//设置第10列(0开始)值Array.setInt(arrayObj, 10, 37);int arrayCast[][][] = (int[][][])array;System.out.println(arrayCast[3][5][10]);}}/**array:[  [   [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  ],   [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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