File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "iterate through a hashMap" Watch "iterate through a hashMap" New topic

iterate through a hashMap

C hurst

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 :

[ 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

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]
It is sorta covered in the JavaRanch Style Guide.
subject: iterate through a hashMap
jQuery in Action, 3rd edition