1. Map Traversal
/The most common Traversal method is the most common. Although it is not complex, it is very important. This is what we are most familiar with. I will not say much about it !!
Public static void work (Map <string, student> map ){
Collection <student> C = map. Values ();
Iterator it = C. iterator ();
For (; it. hasnext ();){
System. Out. println (it. Next ());
}
}
// Use keyset for traversal. Its advantage is that it can be worth the values you want based on the key you want, making it more flexible !!
Public static void workbykeyset (Map <string, student> map ){
Set <string> key = map. keyset ();
For (iterator it = key. iterator (); it. hasnext ();){
String S = (string) it. Next ();
System. Out. println (Map. Get (s ));
}
}
// A complicated Traversal method is provided here ~~ He is very violent. He is so flexible that he can get whatever he wants ~~
Public static void workbyentry (Map <string, student> map ){
Set <map. Entry <string, student> set = map. entryset ();
For (iterator <map. Entry <string, student> it = set. iterator (); it. hasnext ();){
Map. Entry <string, student> entry = (Map. Entry <string, student>) it. Next ();
System. Out. println (entry. getkey () + "--->" + entry. getvalue ());
}
}