Public static void main (string [] ARGs ){
Map <string, string> map = new hashmap <string, string> ();
Map. Put ("1", "value1 ");
Map. Put ("2", "value2 ");
Map. Put ("3", "value3 ");
// The first type is commonly used. The second value is used.
System. Out. println ("Traverse Key and value through map. keyset :");
For (string key: map. keyset ()){
System. Out. println ("Key =" + key + "and value =" + map. Get (key ));
}
// Type 2
System. Out. println ("Traverse Key and value through map. entryset using iterator :");
Iterator <map. Entry <string, string> it = map. entryset (). iterator ();
While (it. hasnext ()){
Map. Entry <string, string> entry = it. 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 ());
}
// Category 4
System. Out. println ("traverse all values through map. Values (), but not key ");
For (string V: map. Values ()){
System. Out. println ("value =" + V );
}
}