1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
4. Java 5提供了ConcurrentHashMap,它是HashTable的替代,比HashTable的扩展性更好。
5. "hashmap allows a null key(only one is allowed) and many null values"
这里的null value很好理解,但是null key我貌似没咋见过。google之, 找到一个很生动的例子 ,如下:
"
One real life scenario where even a "null" can convey information.
I am working on a project where I have "jobs" (e.g. copy some data from some place to another). I also have a "schedule" which can be associated to the "jobs". The "schedule" contains information on at what time the job should be executed and when should it be repeated.
There is a simple check which we have put in. If the job schedule is null, we execute the job only once. Else we execute it as per schedule.
"
6. note that if a HashMap is modified, iterators pointing to it are rendered invalid.
参考链接:
1 http://www.coderanch.com/t/385836/java/java/HashMap-add-NULL-key