By mistake, we found that hashmap uses the following format to traverse the entire hashmap hashtable in a loop.
Each element in the returned set isMap.EntryType.
Private hashtable <string, string> emails = new hashtable <string, string> ();
// Method 1: entryset ()
// Iterator it = emails. entryset (). iterator ();
// While (it. hasnext ()){
// Map. Entry M = (Map. Entry) it. Next ();
// Logger.info ("email-" + M. getkey () + ":" + M. getvalue ());
//}
// Method 2: directly recycling
For (Map. Entry <string, string> M: emails. entryset ()){
Logger.info ("email-" + M. getkey () + ":" + M. getvalue ());
}
// Method 3: Use keyset ()
Iterator it = emails. keyset (). iterator ();
While (it. hasnext ()){
String key;
Key = (string) it. Next ();
Logger.info ("email-" + key + ":" + emails. Get (key ));
}
// Method 5: Use keyset () (04.29)
For (Object M: emails. keyset ()){
Logger.info ("email-" + M + ":" + emails. Get (m ));
}
In addition, we can convert hashmap into a collection and then iterate the output, but the obtained object
Map AA = new hashmap ();
AA. Put ("tmp1", new object (); // append with the same function.
AA. Remove ("temp1"); // Delete
For (iterator I = AA. Values (). iterator (); I. hasnext ();){
Object temp = I. Next ();
} // Traverse
To complete the internal sorting of elements containing the treeset
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 ("");
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. getkey () + "---" + 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 ));
}
}