my dog learned polymorphism
The moose likes Java in General and the fly likes HasMap iteration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "HasMap iteration" Watch "HasMap iteration" New topic

HasMap iteration

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 980

I have a map returned from a function.

Now I wish to get the keys and values from this map..

But i dont have any idea about both the keys as well as values...

I can iterate about the map and get all the values using .get(key);

but how shall i get the keys in the first place..

A Kumar
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
HashMap provides keySet(), values(), and entrySet() that can all be iterated. The last one holds Map.Entry objects with getKey(), getValue(), and setValue().
Sripathi Krishnamurthy
Ranch Hand

Joined: Mar 07, 2005
Posts: 232
you can also use this way.

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 980

Did the way u guys mentioned ...

I agree. Here's the link:
subject: HasMap iteration
It's not a secret anymore!