Java锯齿数组 [英] Java Jagged Array

查看:160
本文介绍了Java锯齿数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的作业要求我们使用锯齿形数组来存储二维布尔矩阵的值.锯齿状数组是否有内置的Java类,还是我必须使用ArrayLists数组手动创建它?

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 going to have to manually create it with an Array of ArrayLists?

推荐答案

在Java中,二维数组是一维数组对象的数组.每个一维数组可以有不同的长度,这意味着您可以立即使用锯齿状的数组.

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.

例如,以下是完全有效的Java,并打印出3 5 3 4:

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);

这篇关于Java锯齿数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆