wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes iterate through a hashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "iterate through a hashMap" Watch "iterate through a hashMap" New topic
Author

iterate through a hashMap

C hurst
Greenhorn

Joined: Nov 21, 2002
Posts: 4
Hi all,
I was wondering which is the best way of iterating through a hashmap. I cannot use iterator as it isn't define for HashMap. Should I cast the hashMap to some other data structure and iterate through that.


Regards <img src="smile.gif" border="0"> <br />Ciaran
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
if you're only interested in the values :

T.
[ February 04, 2003: Message edited by: Don Kiddick ]
Neil Laurance
Ranch Hand

Joined: Jul 18, 2002
Posts: 183
Try something like:

Cheers, Neil
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Take a look at Section 12.3 of David J. Eck's Introduction to Programming Using Java. About a third of the way down the page is the "Views, SubSets, and SubMaps" section that discusses iterating through all of the associations in a Map.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: iterate through a hashMap