开发者

Best efficient data structure to store object in Android application

开发者 https://www.devze.com 2023-01-15 10:00 出处:网络
I want to build a data structure in myapplication to store many entries indexed by keys. Eac开发者_JS百科h entry has several parameters to retrieve and update.

I want to build a data structure in my application to store many entries indexed by keys. Eac开发者_JS百科h entry has several parameters to retrieve and update.

Could you suggest me which structure is most efficient among these following ones:

  • hashmap
  • SQL Lite
  • hashtable
  • others

Thanks in advance.


If it is a simple key->value relationship then a hashtable or even nosql database is best. However, it sounds like you are storing a key->(value,value,value,value), in this case i would use a sql database, although this is not relational. The key would be your primary key, it doesn't have to be an INTEGER it could be any datatype. You must make sure that your key column is at least UNIQUE although setting it as your primary key will do this automatically, or you could run into problems.

If this is more of a tree structure you might not want to use a sql database. If yo could give an example of the data you want to store and its relationships i can give you a better answer. With the information I have, I'd use sqlite.


If the data doesn't fit in memory, the most common approach is to use SQLite. There are other (more exotic) solutions of course, like using another database (for example the H2 database).

If the data fits in memory, use a hash table. java.util.Hashtable and java.util.HashMap are basically the same, but HashMap is a bit faster (because it's not synchronized). In this case, you may still need to persist the data however, which might be slow if you want to store / read everything in one step.

0

精彩评论

暂无评论...
验证码 换一张
取 消