如何在Java中获取2D数组的行数和列数? [英] How to get rows and columns count of a 2D array in Java?

查看:94
本文介绍了如何在Java中获取2D数组的行数和列数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Java中的数组,我们可以使用array_name.length获得数组的length.同样,如何获得 2D 数组的行数和列数?

For an array in Java, we can get the length of the array with array_name.length. Similarly, how would one get the number of rows and columns of a 2D array?

推荐答案

好吧,您可能希望array_name.length用于获取行数,而array_name[0].length用于列.也就是说,如果您这样定义数组:

Well you probably want array_name.length for getting the count of the rows and array_name[0].length for the columns. That is, if you defined your array like so:

T[][] array_name = new T[row][col];
array_name.length // row
array_name[0].length // col

这篇关于如何在Java中获取2D数组的行数和列数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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