• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Storing key-value pairs: Better apporaches for storing and reading?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a requirement where I have key value pairs (key, value). There can be lakhs of such key value pairs. I need to decide upon an approach, whether i should store these in a normal text file or a XML file. I will have to read these (key, value) pairs from the file (text or XML or any other file format) form a HashMap and save these values to database.

Which approach is better storing in text file, then again reading through lakhs of records, tokenize on ',' and form the hashmap, or have a XML file with key value nodes and parse it and form hashmap. Also is it better to have properties file and have use java Properties api.

Thanks
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Maya Dolas " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cant see what a HashMap has to do with the problem.

IF you have more key-value pairs than will fit in memory as a hashmap THEN a database will have to be used.

IF your hashmap fits in memory you can serialize it to disk as a serialized Java object - this is surprisingly fast.

It seems to me that the choice between a properties style line by line text file and XML depends on how you are going to edit the file. Having said that, parsing the properties style will be LOTS faster.

Bill

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might also consider a key/value pair database, like HeliDB (which also implements the Map interface).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic