Difference between Hashmap and Hashtable?
- HashMap is non-synchronized. Hashtable is synchronized.
- HashMap allows multiple threads where as hashtable doesn't
- HashMap is not thread-safe where as hashtable is.
- HashMap allows one null key and any number of null values. Hashtable doesn’t allow null keys and null values.
Note: We can make the HashMap as synchronized by calling this code
Map m = Collections.synchronizedMap(hashMap) [or] can be used ConcurrentHashMap for thread safe. HashMap throws ConcurrentModificationException when if other thread try to add/modify the contents of Object
0 comments:
Post a Comment