In Java, an empty string can be used as the key of hashmap with the string type as the key, for example:
Public static void main (string [] ARGs) {// todo auto-generated method stubsystem. out. println ("----->"); hashmap <string, string> mfilecache = new hashmap <string, string> (); mfilecache. put ("", "Null String"); mfilecache. put ("ABC", "ABC string"); system. out. println ("[" + mfilecache. get ("") + "]"); system. out. println ("[" + mfilecache. get ("ABC") + "]"); system. out. println ("<-----");}
The output result is as follows:
----->
[Null String]
[ABC string]
<-----
In addition, hashmap also runs the null key and null value. The following describes hashmap in JDK:
Java. util. hashmap <K, V>
Type parameter:
-
K
-The type of the key maintained by this ing
-
V
-Type of the mapped Value
Hash table-basedMapInterface implementation. This implementation provides all the optional ing operations and allows the useNullValue andNullKey. (Except for non-synchronization and allow the use of null,HashmapClass andHashtable.) This class does not guarantee the order of mappings, especially it does not guarantee that the order remains unchanged.