Difference between ContentValues ββand HashMap?
1) HashMap is a generic utility class which is in java.util ContentValues , on the other hand is a specific class in android.content designed to match Android classes like SQLiteDatabase and ContentResolver
Note. that they implement different interfaces according to the above notation:
- HashMap
implements Cloneable and Serializable
- ContentValues
implements Parcelable
2) ContentValues
has a member HashMap
with String
:
private HashMap<String, Object> mValues
3) ContentValues
has a number of methods to get and enter typed values ββ(like getAsFloat (), etc.)
Conclusion
You can consider it ContentValues
as a wrapper HashMap
for storing typed values, usually along with Android SQLiteDatabase or ContentResolver .
What he
source to share
first look at the soruce code of the ContetntValue.java class in the following link
as you can see, this class has a Hash map variable (mValues), and almost all methods work with it. for example, when you create a ContentValue object, you call the ContentValue constructor, and in that const object of the mValue object is created, for example on line 52:
public ContentValues ββ(int size) {mValues ββ= new HashMap (size, 1.0f); }
or when you call the put method of the contentValue object as a whole, you put the value into a HashMap object (mValues), like line 95:
public void put (String key, String value) {mValues.put (key, value); }
so why use ContentValue ?! ContentValue has some useful methods that make it better for working with something like ContentResolver. One of the most important methods is writeToParcel ():
writeToParcel (Parcel parcel, int flags)
you can read about all these methods in the android doc:
http://developer.android.com/reference/android/content/ContentValues.html
hope this comment helps you and sorry for my bad english.
source to share