can java.util.properties replace HashMap effectively ?

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 :

[CODE]

HashMap child = new HashMap();

child.put("b","1")

HashMap parent = new HashMap();

parent.put("a","1");

parent.put("child",child);

[/CODE]

so now i can access child through parent.

[CODE] String num = parent.get("child").get("b");[/CODE]

can i do a similar thing with java.util.properties

[1134 byte] By [Arjun_jga] at [2007-11-26 23:59:02]
# 1
a=1b=aString key = prop.getProperty("b");String value = prop.getProperty(key);This one ?
rym82a at 2007-7-11 15:47:33 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

Properties is a special case of Hashtable, holding only Strings as keys and values. Internally it is a hashtable.

Thus it can not do what you want it to do, i.e. a hierarchical set of properties, you have either to define an own structure or use Hashmap or Hashtable for it.

By the way your code example will not work (beside the missing ; in the second line, you have to cast parent.get("child") to HashMap and the result of the last get to String in order to make it run ;

String num = (String) ((java.util.HashMap) parent.get("child")).get("b");

g_magossa at 2007-7-11 15:47:33 > top of Java-index,Java Essentials,Java Programming...
# 3
It was just a sample code. So i was not particular abt the sintax. and yes i meant the same wayie.a=1b=aString key = prop.getProperty("b");String value = prop.getProperty(key);Thanks,Arjun.
Arjun_jga at 2007-7-11 15:47:33 > top of Java-index,Java Essentials,Java Programming...
# 4
So you got the solution ?Give the duke stars to people helped you.
rym82a at 2007-7-11 15:47:33 > top of Java-index,Java Essentials,Java Programming...
# 5
alternatively, use Map < String, String > myMap = new HashMap < String, String > ();
georgemca at 2007-7-11 15:47:33 > top of Java-index,Java Essentials,Java Programming...