• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help regarding getting values based on keys in HashMap

 
Avinash Sridhar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

This is how I am populating questions to the hashmap

quesAnsHash.put(counter++, question);

and this is how I am trying to get at the values for the keys and display them



I am able to get the key. But i am not able to get the value corresponding to the key. What is it that is going wrong here?.

Please let me know. Help would be greatly appreciated.

Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell us what happens?
 
Avinash Sridhar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response.

Only the keys are getting displayed, but the value corresponding to the keys are not getting displayed at all.

IS this information sufficient.

Thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Avinash Sridhar:
...Only the keys are getting displayed, but the value corresponding to the keys are not getting displayed at all.

IS this information sufficient...

We would need to see the code that is supposed to be displaying these things. What you've shown should work...
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope order is not important.
 
Avinash Sridhar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies, The order is important, and i have used LinkedHashMap. I got this to work. Thanks a lot for spending time over this.

avinash
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have managed to get a Set which only contains the keys. Look back in the API for HashMap and you should be able to find a set with entries in; go through the list of methods. You may have to click on the links to find other classes.

[edit]You seem to have got more help while I was writing this post.[/edit]
[ April 11, 2007: Message edited by: Campbell Ritchie ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic