Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ContentValues and HashMap?

Tags:

android

What is the difference between ContentValues and HashMap? If there is a difference, what is the best analogy to describe it?

like image 910
noobie Avatar asked Dec 14 '22 17:12

noobie


1 Answers

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

like image 60
sberezin Avatar answered Dec 17 '22 06:12

sberezin