根据Java文档的Hashtable
类:在Hashtable中获取空检查()操作
This example creates a hashtable of numbers. It uses the names of the numbers as keys:
Hashtable<String, Integer> numbers
= new Hashtable<String, Integer>();
numbers.put("one", 1);
numbers.put("two", 2);
numbers.put("three", 3);
To retrieve a number, use the following code:
Integer n = numbers.get("two");
if (n != null) {
System.out.println("two = " + n);
}
为什么它使用get期间if (n != null) {
在上面的代码()操作时的Hashtable不允许在键和值空?
如果它是为HashMap编写的,那么它会好的,因为HashMap允许在键和值中使用空值,但为什么它将它用于Hashtable?