File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve values using hashmap

 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have stored key values in a hash map.

I would now like to retrieve the values back to be printed.
How do I do that?
Please help as I am very new to this field.
Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look through the Map doc for a method that "returns a set view of the keys contained in this map." Then you can get an iterator on the set and work through the keys one at a time. Does that do what you need?
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish I was able to get that onto my head right away.. but I would have preferred some code instead, showing the same.
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody to help please?
 
John Dell'Oso
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stan gave you a very good clue - a method that "Returns a set view of the keys contained in this map."

I'll give you another small hint - the method name is keySet(). Once you have a set of keys from your map, you can iterate over the set of keys and retrieve the values.

Regards,
JD
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it something like this?

After this, how do I get to display them?
That is where I am stuck!
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could just get the list of values directly using the values() method.
[ July 05, 2007: Message edited by: Joanne Neal ]
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let me be clearer. This is how it is.

I need to populate a JSF dropdown menu from the database using HashMap.

I get the values from the dB and put them in a hashmap in MemberSearchUtil class, this way:


In the Action class, how do I get the state_list values back is my problem.


Kindly help.
 
John Dell'Oso
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some code that may help you. It's not a very good example (it's late here Down Under) but I think it sort of demonstrates what you're looking for.



I'm not sure what version of the JDK you're using (or if you use generics), so here's a version without the generics:



Hope this helps.

Regards,
JD
[ July 05, 2007: Message edited by: John Dell'Oso ]
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I tried what you suggested. In a list of 50, it goes to the 15th key and prints only the 15th value.!! Where am I going wrong??
 
Aparna Ram
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved it. Thanks for all the help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic