如题所述
代ç å¦ä¸ï¼
import java.lang.reflect.Array;
public class ArrayTest {
/*
* 使ç¨Arrayç±»å¨æå建å¤ç»´æ°ç»
*/
public static void main(String[] args) {
//å建ä¸ä¸ªå ç´ ç±»åStringï¼ç»´åº¦ä¸º[5][10]çæ°ç»
Object arr=Array.newInstance(String.class, 5,10);
//为äºç»´æ°ç»èµå¼
//è·å第ä¸ç»´åº¦ä¸º4çæ°ç»
Object firstIndex=Array.get(arr, 4);
Array.set(firstIndex, 6, "zhangxun");
Array.set(firstIndex,7,"lili");
Array.set(firstIndex,9,"wangs");
//è·å第äºç»´åº¦ä¸º3çæ°ç»
Object new_firstIndex=Array.get(arr, 3);
Array.set(new_firstIndex, 5, "mada");
//å°arræ°ç»è½¬æ¢ä¸ºarr_sträºç»´æ°ç»å¹¶è¾åº
String[][] arr_str=(String[][])arr;
System.out.println(arr_str[4][6]);
System.out.println(arr_str[4][7]);
System.out.println(arr_str[4][9]);
System.out.println(arr_str[3][5]);
}
}
import java.lang.reflect.Array;
public class ArrayTest {
/*
* 使ç¨Arrayç±»å¨æå建å¤ç»´æ°ç»
*/
public static void main(String[] args) {
//å建ä¸ä¸ªå ç´ ç±»åStringï¼ç»´åº¦ä¸º[5][10]çæ°ç»
Object arr=Array.newInstance(String.class, 5,10);
//为äºç»´æ°ç»èµå¼
//è·å第ä¸ç»´åº¦ä¸º4çæ°ç»
Object firstIndex=Array.get(arr, 4);
Array.set(firstIndex, 6, "zhangxun");
Array.set(firstIndex,7,"lili");
Array.set(firstIndex,9,"wangs");
//è·å第äºç»´åº¦ä¸º3çæ°ç»
Object new_firstIndex=Array.get(arr, 3);
Array.set(new_firstIndex, 5, "mada");
//å°arræ°ç»è½¬æ¢ä¸ºarr_sträºç»´æ°ç»å¹¶è¾åº
String[][] arr_str=(String[][])arr;
System.out.println(arr_str[4][6]);
System.out.println(arr_str[4][7]);
System.out.println(arr_str[4][9]);
System.out.println(arr_str[3][5]);
}
}
温馨提示:答案为网友推荐,仅供参考