Package test;
Import java. util. collections;
Import java. util .*;
Public class testlist {
Public static void main (string [] ARGs ){
Map map = new hashmap ();
Map. Put ("1", "hello ");
Map. Put ("2", "world ");
Map. Put ("3", "nihao ");
Map. Put ("4", "Shijie ");
Map. Put ("5", "Zhong ");
Map. Put ("6", "Guo ");
Iterator = map. keyset (). iterator ();
While (iterator. hasnext ()){
Object key = iterator. Next ();
Object value = map. Get (key );
System. Out. println (Key + "--" + value );
}
String STR = (string) map. Put ("1", "linweihan"); // replace the value of Index 1 and return the old value.
System. Out. println (STR );
System. out. println ("========================================== ========= ");
Iterator iterator1 = map. keyset (). iterator ();
While (iterator1.hasnext ()){
Object key = iterator1.next ();
Object value = map. Get (key );
System. Out. println (Key + "--" + value );
}
}
}
========================================================== =====
Result:
3 -- nihao
5 -- Zhong
2 -- World
4 -- Shijie
6 -- Guo
1 -- hello
Hello
========================================================== ======
3 -- nihao
5 -- Zhong
2 -- World
4 -- Shijie
6 -- Guo
1 -- linweihan