哪个在2D数组,行或列中首先出现? [英] Which comes first in a 2D array, rows or columns?
本文介绍了哪个在2D数组,行或列中首先出现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建2D数组时,如何记住是先指定行还是列?
When creating a 2D array, how does one remember whether rows or columns are specified first?
推荐答案
Java被认为是 row major,意思是它先行。这是因为2D数组是数组数组。
Java is considered "row major", meaning that it does rows first. This is because a 2D array is an "array of arrays".
例如:
int[ ][ ] a = new int[2][4]; // Two rows and four columns.
a[0][0] a[0][1] a[0][2] a[0][3]
a[1][0] a[1][1] a[1][2] a[1][3]
It也可以更像这样显示:
It can also be visualized more like this:
a[0] -> [0] [1] [2] [3]
a[1] -> [0] [1] [2] [3]
第二个插图显示数组数组方面。第一个数组包含 {a [0]和[1]}
,每个数组都包含四个元素, {[0] [1] [2] [3]}
。
The second illustration shows the "array of arrays" aspect. The first array contains {a[0] and a[1]}
, and each of those is an array containing four elements, {[0][1][2][3]}
.
TL; DR摘要:
Array[number of arrays][how many elements in each of those arrays]
有关更多说明,另请参阅 数组 - 2 -dimensional 。
For more explanations, see also Arrays - 2-dimensional.
这篇关于哪个在2D数组,行或列中首先出现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文