in JDK1.4
Map map = new HashMap ();
Iterator it = Map.entryset (). iterator ();
while (It.hasnext ()) {
Map.entry Entry = (map.entry) it.next ();
Object key = Entry.getkey ();
Object value = Entry.getvalue ();
}
JDK1.5, the application of new characteristics For-each cycle
Map m = new HashMap ();
For (Object O:map.keyset ()) {
map.get (o);
}
Each element in the returned set is a map.entry type.
Private hashtable<string, string> emails = new hashtable<string, string> ();
In addition, we can change the HashMap to a set collection, then iterate the output, but the resulting object
Method One: Use 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: jdk1.5 support, with EntrySet () and For-each Loop () for
(map.entry<string, string> m:emails.entryset ()) {
Logger.info ("email-" + m.getkey () + ":" + m.getvalue ());
}
Method Three: Use Keyset ()
Iterator it = Emails.keyset (). iterator ();
while (It.hasnext ()) {
String key;
key= (String) It.next ();
Logger.info ("email-" + key + ":" + emails.get (key));
}
Method Five: jdk1.5 support, with keyset () and For-each loops for
(Object m:emails.keyset ()) {
logger.info ("email-" + m+ ":" + Emails.get (m));
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
To a complete, treeset element that contains the interior sort.
public static void Main (string[] args) {arraylist<string> list = new arraylist<string> ();
hashmap<object,object> hash = new hashmap<object,object> ();
treemap<object,object> TreeMap = new treemap<object,object> ();
List.add ("a");
List.add ("B");
List.add ("C");
Hash.put (3, 3);
Hash.put (4, 4);
Hash.put (5, 5);
Hash.put (6, 6);
Hash.put (1, 1);
Hash.put (2, 2);
Treemap.put (1, 1);
Treemap.put (2, 2);
Treemap.put (3, 3);
Treemap.put (4, 4);
Treemap.put (5, 5);
Treemap.put (6, 6);
List traversal for (String m:list) {System.out.println (M); }//HashMap EntrySet () Traversal for (map.entry<object,object> M:hash.entryset ()) {System.out.println (M.getke
Y () + "---" +m.getvalue ());
//hashmap keyset () Traversal for (Object M:hash.keyset ()) {System.out.println (m+ "---" +hash.get (m)); }//TreeMap keyset () Traversal for (Object M:treemap.keyset ()) {SYSTEM.OUt.println (m+ "---" +treemap.get (m)); }
}