是Android中的SQLite cursor.getCount昂贵的操作

Android设备上执行SQLite cursor.getCount()是否是昂贵的操作?

哪个更快:

Cursor cursor = db.rawQuery(sql, null); int length = cursor.getCount(); final List items = new ArrayList(length * 2); // need maybe 2 items per row if (cursor.moveToFirst()) { // loop trough the query result do { ... 

要么

 Cursor cursor = db.rawQuery(sql, null); final List items = new ArrayList(); // capacity is 0 by default on android if (cursor.moveToFirst()) { // loop trough the query result do { 

如果你比较两个代码样本执行所需的时间,你会发现它是相同的,因为Cursor.moveToFirst()最终调用SQLiteCursor.getCount()