views:

84

answers:

2

I want to build a data structure in my application to store many entries indexed by keys. Each 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.

+1  A: 

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.

Rook
Thanks. It is of great help.
aladine
@aladine your welcome.
Rook
A: 

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.

Thomas Mueller