Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

How to create the nested hashMap dynamically

 
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
Posts: 23886
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Posts: 23886
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
Posts: 23886
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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.
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic