entrySet

method:

1.public K getKey (): Gets Entry object key.
2.public V getValue (): Get Value Entry object.
3.public Set <Map.Entry <K, V >> entrySet (): Gets to the collection Map collection of key-value pairs for all objects (Set collection).

Code:

. 1  Import the java.util.HashMap;
 2  Import a java.util.Map;
 . 3  Import java.util.Set;
 . 4  
. 5  public  class EntryDemo {
 . 6      public  static  void main (String [] args) {
 . 7          // Create Map objects set and 
. 8          the HashMap <String, String> hashMap '= new new the HashMap <> ();
 . 9          hashMap.put ( "Ma", "Ali Baba" );
 10          hashMap.put ( "Ma", "Tencent" );
 . 11          hashMap.put ( "Wang Jianlin," "Wanda" );
12          // get all of the Entry objects
13 is          the Set <of Map.Entry <String, String entries It >> = TreeMap.entrySet ();
 14          // traverse the object to get each entry 
15          for (of Map.Entry <String, String> entry: entries It) {
 16              the System.out. the println (entry.getKey () + ":" + entry.getValue ());
 . 17          }
 18 is  
. 19  
20 is      }
 21 is }

 

Guess you like

Origin www.cnblogs.com/0error0warning/p/12528461.html