Style or performance: "new ContentValues ββ()" VS "contentValues.clear ()"
I'm never sure, so I usually find myself inconsistent.
Which is more efficient:
- Re-create
ContentValues
many times - Create
ContentValues
once and then callclear()
each time before using it
Example (1) :
while (condition) {
ContentValues values = new ContentValues();
// Add to values
// Create an operation
}
// Execute a batch of operations
Example (2) :
ContentValues values = new ContentValues();
while (condition) {
values.clear();
// Add to values
// Create an operation
}
// Execute a batch of operations
Assuming a large enough number of iterations to make a difference.
+3
source to share
2 answers
A typical use case for ContentValues ββlooks like this:
// Defines an object to contain the new values to insert
ContentValues mNewValues = new ContentValues();
/*
* Sets the values of each column and inserts the word. The arguments to the "put"
* method are "column name" and "value"
*/
mNewValues.put(UserDictionary.Words.APP_ID, "example.user");
mNewValues.put(UserDictionary.Words.LOCALE, "en_US");
mNewValues.put(UserDictionary.Words.WORD, "insert");
mNewValues.put(UserDictionary.Words.FREQUENCY, "100");
Now you how you use it for your requirements is up to you depending on what your logic requires from hasMore()
0
source to share