permaculture playing cards*
The moose likes Beginning Java and the fly likes does proprties file has the ability of hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "does proprties file has the ability of hashmap" Watch "does proprties file has the ability of hashmap" New topic
Author

does proprties file has the ability of hashmap

Arjun Karthick
Ranch Hand

Joined: Jan 04, 2007
Posts: 77
Hi everyone,
My requirement is to store the name/value pair of the configuration.they are divided into different section.that is similar name/value pair are grouped under a section.

This was handled by using hashMap. But now i want to use java.util.properties for the same requirement as in the earlier case i had many section which lead to many HashMap.And finally ended up to lot number of object in the runtime.

the problem is hashmap could hold<object,object> So i could hold HashMap in the value of a key. And then get the access of that map through this value. But properties hold<String,String> ( upto my learning about properties). Is it possible to hold a reference of the another entry inthe property's value.
For example :

so now i can access child through parent.


can i do a similar thing with java.util.properties
regards,
Arjun.
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
java.util.Properties inherits java.util.Hashtable hence you will be able to use "put" method. However javadocs of Properties strongly discourages the use of these methods to avoid insertion of objects other than String. In this case you could directly use Hashtable instead of Properties.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41104
    
  45
Why do you want to use the Properties class? Its main advantage over Hashtable is its ability to read and store from/to files; if you're not going to do that, there's little point in using Properties. And yes, Properties is limited to strings, precisely because it writes to disk.

Of course, a HashMap or Hashtable can be serialized to disk as well, just not in a human-readable format.


Ping & DNS - my free Android networking tools app
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you want a tree structure plus the ability to easily read/write to/from disk, have you considered an XML document?
[ April 04, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Arjun Karthick
Ranch Hand

Joined: Jan 04, 2007
Posts: 77
But, does using XML document cause a performance hit if the values are loaded at runtime as it has to do parseing at runtime?

Thanks
Arjun.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41104
    
  45
Parsing an XML file is indeed likely to be a bit slower than reading a comparable properties file, but unless the amount of data is large (say, tens of thousands of elements) or large numbers of files are read (thousands), I wouldn't worry about that.
Arjun Karthick
Ranch Hand

Joined: Jan 04, 2007
Posts: 77
Thanks for your suggestion.
The data are in hundreds. So i can go for XML document.

Thanks,
Arjun.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: does proprties file has the ability of hashmap
 
Similar Threads
Composite foreign key causing "object is not an instance of declaring class"?
Improving An Algorithm
Using object as keys in maps
apply-template params vs accessing parent attributes
Simple J2SE 5.0 Tiger Notes