1)Hashtable is synchronized whereas hashmap is not synchronised.
2)Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn't. If you change the map while iterating, you'll know.
3)HashMap permits null values in it, while Hashtable doesn’t permits null values. (HashMap allows null values as key and value whereas Hashtable doesn't allow nulls).
4)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.
No comments:
Post a Comment