【发布时间】:2011-07-03 02:43:35
【问题描述】:
如果可能的话,我想知道如何创建 n 个相同大小的数组。帮助将不胜感激。例如:我想创建 10 个元素数量相同的数组,而不必一个一个地创建它们:int[] a = new int[]。希望现在更清楚了。
我在其中一个 cmets 中的一个问题是 +-“我如何对数组行进行排序以用于行/列用于列”。我想通了——也许有人会觉得它有用。
int[] sortarr = new int[5]; //create array to transfer data from row to new array
for (int i=0; i<N; i++){
for (int j=0; j<5; j++){
sortarr[j] = hands[i][j]; //transfer the data from 2D array's row to sortarr
}
Arrays.sort(sortarr); //sort the row's data
for (int x=0; x<5; x++){
hands[i][x] = sortarr[x]; //transfer the data back to 2D array
}
}
也许这很明显,但我希望这会对那里的人有所帮助。
【问题讨论】:
-
你能澄清你的问题吗?我不明白你想做什么。
-
您能提供更多信息吗?你需要可变数量的数组吗?
标签: java arrays sorting multidimensional-array