【发布时间】:2016-05-01 02:03:47
【问题描述】:
我有
String[] x1 = new String[] { "05:30", "07:20", "13:30", "21:30"};
String[] x2 = new String[] { "08:30", "01:20"};
String[] x3 = new String[] { "12:30", "00:20", "13:54"};
我从数据库中收到 x1 或 x2 或 x3 名称。
String get_x = null;
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
get_x = cursor.getString(0); // get_x will have value x1 or x2 or x3
} while (cursor.moveToNext());
}
然后我想得到返回的 x[1 or 2 or 3] 的大小 例如。 int size = x1.length,其中 x1 是 get_x 字符串的值。
我试过了
int size = get_x.length;
但不工作。 'size' 将等于 get_x 的长度,而不是 x1.length 的长度
【问题讨论】:
-
什么是get_x?您将其定义为 String,因此 String.valueOf 似乎是多余的。
-
String get_x = new String();是多余的; "new String()" 将被回收,因为 get_x 仅分配在下面几行。
-
我编辑了但还是不行。
-
大小是什么意思?你想知道你的数组中有多少个值?就像在 x1 中你有 4 个?
-
@Roman Rozenshtein,是的,完全正确。
标签: android