wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help regarding getting values based on keys in HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help regarding getting values based on keys in HashMap" Watch "Help regarding getting values based on keys in HashMap" New topic
Author

Help regarding getting values based on keys in HashMap

Avinash Sridhar
Greenhorn

Joined: Apr 11, 2007
Posts: 6
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

Joined: Feb 07, 2005
Posts: 2367
Could you tell us what happens?
Avinash Sridhar
Greenhorn

Joined: Apr 11, 2007
Posts: 6
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

Joined: Aug 31, 2004
Posts: 11343

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...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I hope order is not important.
Avinash Sridhar
Greenhorn

Joined: Apr 11, 2007
Posts: 6
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

Joined: Oct 13, 2005
Posts: 39053
    
  23
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 ]
 
GeeCON Prague 2014
 
subject: Help regarding getting values based on keys in HashMap