[Logo]
Forums Register Login
How to create the nested hashMap dynamically
Suppose the string is A.B.C.D=123, A.E=11,A.B.C=78
i need the hashmap to be in the format
 

Aman Tandon wrote:Suppose the string is A.B.C.D=123, A.E=11,A.B.C=78
i need the hashmap to be in the format



Can you elaborate what you mean by "hashmap to be in the format"? How does a hashmap get formatted?

Henry
In my case i will got the string array having values like suppose
animal.land.tiger=africa
animal.land.deer=australia

so in this case there will be a nested hashmap of <String, String >
so the main key will be animal, land is child of animal, tiger and deer are the sibblings and have these corresponding values

i have to create the hashmap<String, String> dynamically whenever i got that array

 

Aman Tandon wrote:In my case i will got the string array having values like suppose
animal.land.tiger=africa
animal.land.deer=australia

so in this case there will be a nested hashmap of <String, String >
so the main key will be animal, land is child of animal, tiger and deer are the sibblings and have these corresponding values

i have to create the hashmap<String, String> dynamically whenever i got that array




Still, not completely sure ... but ... I think you are trying to say you want a tree of hashmaps, where the leaves are HashMap<String, String> instances and the branches are HashMap<String, HashMap<String, ?>> instances. IMO, your best option is to use HashMap<String, Object> instances, and your code is then responsible for checking whether the value is a leaf or a branch.

Henry
yeah you is right sir
i am really confused to how to do this..
main key is params
first time if i got the string :->
options.filters.city.name="Delhi"
then hashmap should be like this

if the next string comes up like :->
options.filters.city.pincode="201300"
then params will becomes,

I will be really thankful to you....please help me out
 

Aman Tandon wrote:yeah you is right sir
i am really confused to how to do this..
main key is params
first time if i got the string :->
options.filters.city.name="Delhi"
then hashmap should be like this

if the next string comes up like :->
options.filters.city.pincode="201300"
then params will becomes,

I will be really thankful to you....please help me out




Not exactly sure of the current issue yet. Your latest description is almost the same as you previous one, so I am still of the opinion that your previous design is still fine. Or are you asking about implementation? Meaning the issue is not really related to the design, but how to actually code it?

Henry
issue is cleared already and i already described it sir with exampe....
i have to modify the params hashmap for the strings came up.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 1460 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jun 20, 2018 18:57:48.