This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to create the nested hashMap dynamically  RSS feed

 
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
 
author
Sheriff
Posts: 23586
138
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: 23586
138
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: 23586
138
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!