This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Map.Entry Details help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Map.Entry Details help" Watch "Map.Entry Details help" New topic

Map.Entry Details help

kalpana Kumar
Ranch Hand

Joined: Jul 03, 2003
Posts: 65
Hi all,
I would like to know the advantages of using Map.Entry it is used to get the Set view of the map. But I need much more details regarding the same.
I saw an example in which there is a HashMap and since Iterator cannot be used on HaspMap it is converted into Set using entrySet
While Iterating, (Map.Entry) is used. I would like to know why is that necessary.
Why not a Map be used to get the KeyValue pair. I not getting in the Order in which the values were added into the HashMap too, if I consider that to be the advantage of using Map.entry.

Please help needed.

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
First, HashMap allows you to iterate the keys, the values, or the key/value pairs. Map.entrySet().iterator() is for iterating key/value pairs stored in Map.Entry objects.The reason to use this method is so you don't have to look up the value for each key when iterating keys.

If you need the keys and key/values in the same order as you added them, you'll need to use JDK 1.4's LinkedHashMap class or roll your own.
I agree. Here's the link:
subject: Map.Entry Details help
It's not a secret anymore!