Nonrectangular Arrays(非矩形数组):

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



public class Test {
    public static void main(String[] args) {
        String[ ] str;
        str=new String[2];
        str[0]="aaa";
        str[1]="bb";
       



        String[ ] str1;
        str1=new String[]{"aaa","bbb"};
//        假如写成下一句,就报这个错。Cannot define dimension expressions when an array initializer is provided
//        str1=new String[2]{"aaa","bbb"};
        System.out.println(str1[0]+str1[1]);
       
        String[][] x = new String[3][];
        x[0]=new String[]{"hello","马克-to-win"};
        x[1]=new String[]{"are","you","fine"};
        x[2]=new String[]{"ok"};
        for(int i=0; i<3;i++){
            for(int j=0;j<x[i].length;j++){
                    System.out.println("x["+i+"]["+j+"]"+" is "+x[i][j]);
            }
        }
    }
}

结果:

aaabbb
x[0][0] is hello
x[0][1] is 马克-to-win
x[1][0] is are
x[1][1] is you
x[1][2] is fine
x[2][0] is ok