What is the difference between ContentValues
and HashMap
? If there is a difference, what is the best analogy to describe it?
1)HashMap is a general utility class that resides in java.util.
ContentValues on the other hand is a specific class in android.content designed to comply with Android classes like SQLiteDatabase and ContentResolver
Note that they implement different interfaces according to aforementioned designation:
- HashMap
implements Cloneable and Serializable
- ContentValues
implements Parcelable
2) ContentValues
has a member that is HashMap
with String
keys:
private HashMap<String, Object> mValues
3) ContentValues
has a number of methods to get and put typed values (like getAsFloat() etc)
Conclusion
You may consider ContentValues
as a wrapper of HashMap
to store typed values, usually along with Android SQLiteDatabase or ContentResolver.
That's it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With