How is Hashtable different to Hashmap

Possible Duplicate:
Differences between HashMap and Hashtable?

I've seen hash tables and hash maps used in different code but they look like they do the same thing. Is there a difference between them? Which one should I use in my code?


java.util.Hashtable methods are synchronized , java.util.Hashmap methods are not. If you use Hashtable there will be a performance hit as no two threads will be able to access its methods at the same time. If you care about Thread safety in your app Hashtable is the way to go. if you dont care about thread safety Hashmap is the way to go as it is mor eefficient then hashtable. also java.util.Hashtable doesnt allow any null keys, where as java.util.HashMap allows one null key.


Hashtable is synchronized, where as HashMap is not. This means if you only have a single thread accessing the data, use a HashMap, otherwise use a Hashtable.


HashTable不允许空键,因为hashmap允许一个空键

链接地址: http://www.djcxy.com/p/16348.html

上一篇: 散列表和散列表之间的区别

下一篇: 哈希表如何与哈希表不同?