来看下面这段代码:
public static void main(String[] args) {
Map<String, String> map = new HashMap<>();
Integer a = null;
map.put("aaa", String.valueOf(a));
System.out.println("aaa:"+map.get("aaa").toString());
System.out.println("null".equals(map.get("aaa").toString()));
}
在运行后:
Connected to the target VM, address: '127.0.0.1:64507', transport: 'socket'
aaa:null
true
Disconnected from the target VM, address: '127.0.0.1:64507', transport: 'socket'
Process finished with exit code 0
如上所示:
aaa的value是“null”字符串