File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Storing key-value pairs: Better apporaches for storing and reading? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Storing key-value pairs: Better apporaches for storing and reading?" Watch "Storing key-value pairs: Better apporaches for storing and reading?" New topic
Author

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

Maya Dolas
Greenhorn

Joined: Jul 04, 2007
Posts: 26
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


<b><i>Maya</i></b>
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"Maya Dolas " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42268
    
  64
You might also consider a key/value pair database, like HeliDB (which also implements the Map interface).


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing key-value pairs: Better apporaches for storing and reading?