Hashmap usage [fold] package hashmap; import Java. util. hashmap; import Java. util. hashtable; import Java. util. iterator; import Java. util. linkedhashmap; import Java. util. map; import Java. util. treemap; public class hashmap1 {// initialize private void Init (MAP map, string kind) {If (map! = NULL) {for (INT I = 1; I <6; I ++) {map. put (string. valueof (I), kind + I) ;}}// the private void output (MAP map) {If (map! = NULL) {object key = NULL; object value = NULL; iterator iterater = map. keyset (). iterator (); While (iterater. hasnext () {key = iterater. next (); value = map. get (key); system. out. print (Key + ":" + value + "/t");} system. out. println ("/N") ;}} public static void main (string ARGs []) {hashmap = new hashmap (); hashmap. put ("X", "1"); hashmap. put ("u", "2"); hashmap. put ("Z", "3"); hashmap. put ("H", "4"); hashmap. put ("A", "5"); hashmap. put ("O", "6"); hashmap. put ("g", "7"); hashmap. put ("u", "8"); hashmap. put ("A", "9"); hashmap. put ("N", "10"); hashmap. put ("g", "11"); object key = NULL; object value = NULL; iterator iterater = hashmap. keyset (). iterator (); While (iterater. hasnext () {key = iterater. next (); value = hashmap. get (key); system. out. print (Key + ":" + value + "/t");} system. out. println ("/N");} // declare the hashmap object private void sethashmap () {hashmap = new hashmap (); Init (hashmap, "hashmap"); hashmap. put (null, "the key value is null"); hashmap. put ("the value is null", null); system. out. println ("this is the key and value of the hashmap object:"); output (hashmap);} // declare the hashtable object private void sethashtable () {hashtable = new hashtable (); init (hashtable, "hashtable"); // hashtable. put (null, "the key value is null"); hashtable does not allow the key or the value is null; // hashtable. put ("the value is null", null); system. out. println ("this is the key and value of the hashtable object:"); output (hashtable);} // declare the linkedhashmap object private void setlinkedhashmap () {linkedhashmap = new linkedhashmap (); init (linkedhashmap, "linkedhashmap"); linkedhashmap. put (null, "the key value is null"); linkedhashmap. put ("the value is null", null); system. out. println ("this is the key and value of the linkedhashmap object:"); output (linkedhashmap);} // declare the treemap object private void settreemap () {treemap = new treemap (); // treemap = new treemap (New mysort (); // sort Init (treemap, "treemap") by custom method; treemap. put ("0", "inserted value"); // treemap. put (null, "the key value is null"); treemap does not allow the key or the value is null // treemap. put ("the value is null", null); system. out. println ("this is the key and value of the treemap object:"); output (treemap);} // public static void main (string [] ARGs) {// hashmapdemo TM = new hashmapdemo (); // TM. sethashmap (); // TM. sethashtable (); // TM. setlinkedhashmap (); // TM. settreemap (); // map hashmap = new hashmap (); // hashmap. put (null, "key value is null"); // hashmap. put ("value: NULL", null); // system. out. println ("the number of records for creating a hashmap object element is:" + hashmap. size (); // hashmap. remove (null); // system. out. println ("the number of records for deleting a hashmap object element whose key value is null is:" + hashmap. size ());//}