• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create the nested hashMap dynamically  RSS feed

 
Aman Tandon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aman Tandon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aman Tandon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Aman Tandon
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
issue is cleared already and i already described it sir with exampe....
i have to modify the params hashmap for the strings came up.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!