在二维数组、行还是列中,哪个排在最前面? [英] Which comes first in a 2D array, rows or columns?
本文介绍了在二维数组、行还是列中,哪个排在最前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建二维数组时,如何记住是先指定行还是列?
When creating a 2D array, how does one remember whether rows or columns are specified first?
推荐答案
Java 指定的数组类似于行专业"的数组.配置,这意味着它首先索引行.这是因为二维数组是数组的数组".
Java specifies arrays similar to that of a "row major" configuration, meaning that it indexes 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]
它也可以更像这样:
a[0] -> [0] [1] [2] [3]
a[1] -> [0] [1] [2] [3]
第二幅图显示了数组数组".方面.第一个数组包含{a[0] 和a[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]
更多解释,另见数组- 二维.
For more explanations, see also Arrays - 2-dimensional.
这篇关于在二维数组、行还是列中,哪个排在最前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文