1. Several ways to traverse the map:
Private hashtable<string, string> emails = new hashtable<string, string> ();
Method one: With EntrySet ()
Iterator it = Emails.entryset (). Iterator ();
while (It.hasnext ()) {
Map.entry m= (Map.entry) it.next ();
Logger.info ("email-" + m.getkey () + ":" + m.getvalue ());
}
Method Two: Direct re-circulation
For (map.entry<string, string> m:emails.entryset ()) {
Logger.info ("email-" + m.getkey () + ":" + m.getvalue ());
}
Method Three: With Keyset ()
Iterator it = Emails.keyset (). Iterator ();
while (It.hasnext ()) {
String key;
key= (String) it.next ();
Logger.info ("email-" + key + ":" + emails.get (key));
}
Method Four: First convert the HashMap to set collection, then iterate the output, but the object is obtained
Map AA = new HashMap ();
Aa.put ("Tmp1", New Object ()); Append substitution with the same function.
Aa.remove ("Temp1"); Delete
for (Iterator i = aa.values (). Iterator (); I.hasnext ();) {
Object temp = I.next ();
}//Traversal
Several ways Java traverses a map