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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Map.Entry interface

Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

I am wondering.. is there any meaning of Map DOT Entry(Map.Entry) identifier ?
Source:http://docs.oracle.com/javase/7/docs/api/java/util/Map.Entry.html


OCA7
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4338
    
    7

The DOT means it's an interface nested within the Map interface. It's done like that because it doesn't really have a sensible meaning other than in the context of a Map. It's a class that's used to encapsulate a key/value pair in a Map.

When you're iterating over a Map, you can use the keySet() method to get a collection of the keys, or the values() method to get a collection of the values. But you often want to iterate over both at the same time. In that case the most efficient way is to use the entrySet() method, which returns a collection of Map.Entry objects, so you get both the key and value together.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

 
wood burning stoves
 
subject: Map.Entry interface
 
Similar Threads
Reason to create inner class in an interface
Doubt in a practise question
Problem with stack class
The Java API Documentation and Java 1.7
Generic Collections