wood burning stoves 2.0*
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Map.Entry Details help" Watch "Map.Entry Details help" New topic
Author

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
h_map.entrySet().iterator();
While Iterating, (Map.Entry)iter.next() 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.

Thanks
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: http://aspose.com/file-tools
 
subject: Map.Entry Details help