Package net. nie. test; import Java. util. hashmap; import Java. util. iterator; import Java. util. map; public class hashmaptest {Private Static Map <integer, string> map = new hashmap <integer, string> ();/** 1. hashmap class ing does not guarantee the sequence; some ing can clearly ensure the sequence: treemap class * 2. in the process of traversing the map, map cannot be used. put (Key, newval), map. remove (key (): * remove the element of the current iteration from the collection pointed to by the iterator * to delete the element in the access. **/Public static void main (string [] ARGs) {map. put (1, "one"); map. put (2, "two"); map. put (3, "three"); map. put (4, "four"); map. put (5, "five"); map. put (6, "Six"); map. put (7, "Seven"); map. put (8, "eight"); map. put (5, "five"); map. put (9, "Nine"); map. put (10, "Ten"); iterator <map. entry <integer, string> it = map. entryset (). iterator (); While (it. hasnext () {map. entry <integer, string> entry = it. next (); int key = ent Ry. getkey (); If (Key % 2 = 1) {system. out. println ("delete this:" + key + "=" + key); // map. put (key, "odd"); // concurrentmodificationexception // map. remove (key); // concurrentmodificationexception it. remove (); // OK} // traverses the current map. This new for loop cannot modify the map content because it does not pass the iterator. System. out. println ("------- \ n \ t element traversal of the final map:"); For (map. entry <integer, string> entry: map. entryset () {int K = entry. getkey (); string v = entry. getvalue (); system. out. println (K + "=" + V );}}}