我有一个与动态存储数据相关的问题two Dimensional String Array
,String[][]
. 我在String[i][j]
数组中动态存储数据。这里第一个索引的值是固定的,即i=3
,但第二个索引的值对于所有行都是不同的。
例如,我得到这样的值,
String arrElements[][] = {
{"1"},
{"abc", "xyz", "lkm", "pwd", "srt", "qwert"},
{"1234", "3456"}
};
我得到这样的价值观。即第一行只有一个值,第二行和第三行有任意数量的值。
如果我这样走,
int i = 0, j = 0;
String arrElements[][] = {};
arrElements= new String[3][25];
//What size should I define here.
arrElements[0][0] = "Sahil";
if (a == 0) { //Its just a logical representation of what I might be doing.
// Store the value in second row
arrElements[1][i] = a;
i++;
}
if (a == 1) {
// Store the value in third row
arrElements[2][j] = a;
j++;
}
现在,我将这些值设置在expandable list View
. 如果任何行中的值的数量超过指定的大小,则给出ArrayOutOfBoundException
. 如果大小小于 25,则显示空行。
现在,我不想为数组索引提供硬编码大小限制。有没有更好的方法来处理它。