- package cn.chdany;
- import java.lang.reflect.Array;
- import java.lang.reflect.Method;
- public class Test1 {
- public static void main(String[] args) throws Exception {
- int[] a1 = new int[] { 12, 12, 34 };
- int[][] a2 = new int[][] { { 12, 34 }, { 112, 12, 34 } };
- String[] a3 = new String[] { "asd", "lhm", "zxx", "bxd" };
- String[][] a4 = new String[][] { { "asd", "lhm", "zxx", "bxd" },{ "asd", "lhm", "zxx", "bxd" } };
- String[][][] a5= new String[][][]{{ { "mmm", "lhm", "zxx", "bxd" },{ "asd", "lhm", "zxx", "bxd" } },
- { { "add", "ldm", "zxx", "bxd" },{ "asd", "lhm", "zxx", "bxd" } } };
- printArrys(a1);
- System.out.println();
- printArrys(a2);
- System.out.println();
- printArrys(a3);
- System.out.println();
- printArrys(a4);
- System.out.println();
- printArrys(a5);
- System.out.println();
- }
- private static void printArrys(Object a9) {
- Object obj = a9;
- if (obj.getClass().isArray()) {
- int len = Array.getLength(obj);
- for (int i = 0; i < len; i++) {
- //System.out.println(Array.get(obj, i) + " ");
- printArrys(Array.get(obj, i));
- }
- }
- else{
- System.out.println(obj);
- }
- }
- }
复制代码 |