First: <br/> map = new hashmap (); <br/> iterator iter = map. entryset (). iterator (); <br/> while (ITER. hasnext () {<br/> map. entry entry = (map. entry) ITER. next (); <br/> Object key = entry. getkey (); <br/> Object val = entry. getvalue (); <br/>}< br/> high efficiency. You must use this method later! <Br/> type 2: <br/> map = new hashmap (); <br/> iterator iter = map. keyset (). iterator (); <br/> while (ITER. hasnext () {<br/> Object key = ITER. next (); <br/> Object val = map. get (key); <br/>}< br/> low efficiency. Try to use it less in the future! <Br/> there are two common methods for hashmap traversal: Using keyset and entryset for traversal, but the traversal speed of the two is different. See the example below: <br/> public class hashmaptest {<br/> Public static void main (string [] ARGs )... {<br/> hashmap = new hashmap (); <br/> for (INT I = 0; I <1000; I )... {<br/> hashmap. put ("" I, "thanks"); <br/>}< br/> long BS = calendar. getinstance (). gettimeinmillis (); <br/> iterator = hashmap. keyset (). iterator (); <br/> while (iiter Tor. hasnext ())... {<br/> system. out. print (hashmap. get (iterator. next (); <br/>}< br/> system. out. println (); <br/> system. out. println (calendar. getinstance (). gettimeinmillis ()-BS); <br/> listhashmap (); <br/>}< br/> Public static void listhashmap ()... {<br/> JAVA. util. hashmap = new Java. util. hashmap (); <br/> for (INT I = 0; I <1000; I )... {<br/> hashmap. put ("" I, "thanks"); <br/>}< br/> long BS = Calendar. getinstance (). gettimeinmillis (); <br/> JAVA. util. iterator it = hashmap. entryset (). iterator (); <br/> while (it. hasnext ())... {<br/> JAVA. util. map. entry entry = (Java. util. map. entry) it. next (); <br/> // entry. getkey () returns the key corresponding to this item <br/> // entry. getvalue () returns the value corresponding to this item <br/> system. out. print (entry. getvalue (); <br/>}< br/> system. out. println (); <br/> system. out. println (calendar. getinstance (). gettimei Nmillis ()-BS); <br/>}< br/> the keyset is actually traversed twice, and converted to iterator at one time, the value of the key pair is retrieved from the hashmap at one time. However, entryset only traverses the data for the first time. It puts both the key and value into the entry, so it's faster. <Br/> Note: The hashtable Traversal method is similar to the preceding one! ......