Hashtable Hashmap in Java
Difference between Java Hashtable and Java Hashmap
Hashmap can contains null values as the keys and as well as values.But Hashtable dose not allow null values as keys and values.
Hashtable is syncronized. Hashmap is not syncronized.
Hashtable is one of the original collections of Java but HashMap is added with Java 2, v1.2
HashMap does not guarantee that the order of the map will
remain constant over time.
Class HashMap implements Map interface. Hashtable is a concreate implementation of Dictionary class, is Legacy class, all legacy classes are synchronized.
Only one "null" key is allowed in HashMap but multiple "null" values are allowed in HashMap.
HashMap provides Collection views instead of direct support for iteration via Enumeration objects(as in Hashtable). Collection views greatly enhance the expressiveness of the interface.
HashMap allows you to iterate over keys, values, or key-value pairs whereas a Hashtable does not provide the option.
HashMap provides a safe way to remove entries in the midst of iteration, the older Hashtable
does not.
HashMap retrieval is not in order (random). HashTable provide ordered retrieval.
A hashmap is faster than hashtable.
HashMap has a more complex hashing algorithm then Hashtable. It takes the hash value from the key and then hashes it again (double hashing). This can improve the distribution of the keys and hence the performance of the Map. It does take more time to compute though. This is a useful feature as many hashCode implementations are not very good.
0 comments:
Post a Comment