• 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

does proprties file has the ability of hashmap

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Arjun Karthick
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your suggestion.
The data are in hundreds. So i can go for XML document.

Thanks,
Arjun.
 
reply
    Bookmark Topic Watch Topic
  • New Topic