The map is an interface in Java, and Map.entry is an internal interface to the map.
Map provides a number of common methods, such as keyset (), EntrySet (), and so on.
The return value of the KeySet () method is a collection of key values in map, and the return value of EntrySet () returns a set collection of type Map.entry.
Map.entry is an internal interface to the map declaration, which is generic and defined as entry<k,v>. It represents an entity (a Key-value pair) in a map. The interface has a getkey (), GetValue method.
From the above can be drawn, the common method of traversing map:
1. Map map = new HashMap ();
Irerator iterator = Map.entryset (). iterator ();
while (Iterator.hasnext ()) {
Map.entry Entry = Iterator.next ();
Object key = Entry.getkey ();
//
}
2.Map Map = new HashMap ();
Set keyset= Map.keyset ();
Irerator iterator = Keyset.iterator;
while (Iterator.hasnext ()) {
Object key = Iterator.next ();
Object value = Map.get (key);
//
}
In addition, there is a traversal method, simply traversing the value values, map has a values method, which returns the collection collection of value. By traversing collection, you can also traverse value, such as
Map map = new HashMap ();
Collection C = map.values ();
Iterator Iterator = C.iterator ();
while (Iterator.hasnext ()) {
Object value = Iterator.next ();
}
Java map and map.entry details and uses