Java Jagged Array

Our job assignment requires us to use zigzag arrays to store the values of two-dimensional Boolean matrices Is there a zigzag array of built-in Java classes, or will I have to manually create an array of array arrays?

Solution

In Java, a 2D array is an array of 1D array objects Each 1D array can have different lengths, which means you can use sawtooth arrays

For example, the following is a fully valid Java and prints 3 5 3 4:

int x[][] = {{0,1,2,3,4},{0,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);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>