Map <string, string> map = new hashmap <string, string> ();
Map. Put ("A", "A1 ");
Map. Put ("B", "B1 ");
Map. Put ("C", "C1 ");
1. For (string key: map. keyset ()){
System. Out. println ("Key =" + key + "and value =" + map. Get (key ));
}
2. iterator <map. Entry <string, string> iterator = map. entryset (). iterator ();
While (iterator. hasnext ()){
Map. Entry <java. Lang. String, java. Lang. String> entry = (Map. Entry <java. Lang. String, java. Lang. String>) iterator
. Next ();
System. Out. println ("Key =" + entry. getkey () + "and value =" + entry. getvalue ());
}
// Method 3: Recommended, especially when the capacity is large
System. Out. println ("traversing key and value through map. entryset ");
For (Map. Entry <string, string> entry: map. entryset ()){
System. Out. println ("Key =" + entry. getkey () + "and value =" + entry. getvalue ());
}
Common Methods for Traversing Map