在将对象列表写入数据库时重用相同的ContentValues
实例是否安全?
ContentValues row = new ContentValues();
for (Businessman businessman : aLotOfBusinessmen) {
row.put(BusinessmanEntry.COLUMN_ADDRESS, businessman.getAddress());
row.put(BusinessmanEntry.COLUMN_CASH, businessman.getCash());
db.insert(BusinessmanEntry.TABLE_NAME, null, row);
}
答案 0 :(得分:2)
是
它不仅安全,而且更好,因为您将避免与为循环体的每次执行创建ContentValues
的不同实例相关联的内存分配(以及后续GC)。 / p>