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 KeySet () method return value is a collection of key values in map; The return value of EntrySet () also 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.
ImportJava.util.HashMap;ImportJava.util.Iterator;ImportJava.util.Map.Entry;ImportJava.util.Map; Public classHello { Public Static voidMain (string[] args) {hashmaptest ();} Public Static voidhashmaptest () {System.out.println ("----------------hashmaptest---------------"); Map<String,String> Map1 =NewHashmap<string,string>(); Map1.put ("1", "A"); Map1.put ("2", "B"); Map1.put ("3", "C"); Map1.put ("4", "D"); Map1.put ("5", "E"); Map1.put ("6", "F"); Iterator<entry<string, string>> it =Map1.entryset (). iterator (); while(It.hasnext ()) {Map.entry<String,String> e = (map.entry<string,string>) It.next (); System.out.println (E.getkey ()+ ":" +E.getvalue ()); } System.out.println (MAP1);}}
Java-map.entry