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.
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.
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.
But, does using XML document cause a performance hit if the values are loaded at runtime as it has to do parseing at runtime?
Joined: Mar 22, 2005
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.
Joined: Jan 04, 2007
Thanks for your suggestion. The data are in hundreds. So i can go for XML document.