Hashmap query
3 posts in topic
Flat View  Flat View

Posted By:   sunita_nanda
Posted On:   Friday, April 13, 2007 11:34 AM

I have a hashmap h1 whose key is a string and value is another hasmap.I just want to print h1 on my console.How to read the values and print them

Re: Hashmap query

Posted By:   kulbir_singh  
Posted On:   Tuesday, April 17, 2007 06:09 AM


to read value from the hashmap you just need to pass the key for that particular value
for eg:


this will print the value of that key on console.

Kulbir Singh

Re: Hashmap query

Posted By:   Anonymous  
Posted On:   Monday, April 16, 2007 09:45 AM

With such a model (a hashmap whose values is another hashmap) you should consider to use a MultikeyMap for common.collections.

Re: Hashmap query

Posted By:   Robert_Lybarger  
Posted On:   Saturday, April 14, 2007 10:31 AM

If you want them all, play with this:

/* HashMap h1 defined, populated elsewhere */
for (Object keyObj : h1.keySet()) {

However, if you either know the type of objects the hashmap is storing, you can cast (or you can declare the hashmap to use other than the raw, generic form). Consider:

/* HashMap map defined, populated elsewhere */
for (String keyStr : map.keySet()) {
MyClass mc = map.get(keyStr);
/* do something with 'mc' here */
About | Sitemap | Contact