Java Jagged Array

前端 未结 2 1198
再見小時候
再見小時候 2020-11-28 15:21

Our homework assignment asks us to use a jagged array to store the values of a two dimensional boolean matrix. Is there a built in java class for the jagged array or am I go

2条回答
  •  隐瞒了意图╮
    2020-11-28 15:50

    In Java, a 2D array is an array of 1D array objects. Each 1D array can have different length, which means that you get jagged arrays out of the box.

    For example, the following is perfectly valid Java, and prints out 3 5 3 4:

        int x[][] = {{0,1,2,3,4},{0,1,2},{0,1,2,3}};
        System.out.println(x.length);
        System.out.println(x[0].length);
        System.out.println(x[1].length);
        System.out.println(x[2].length);
    

提交回复
热议问题