Difference between Hashtable and Collections.synchronizedMap(HashMap)

前端 未结 6 2058
小蘑菇
小蘑菇 2020-12-04 14:41

As far as I know, java.util.Hashtable synchronizes each and every method in the java.util.Map interface, while Collections.synchronizedMap(hash_map) returns a wrapper object

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 14:54

    Another point of difference to note is that HashTable does not allow null keys or values whereas HashMap allows one null key and any number of null values. Since synchronizedMap is wrapper over HashMap, its behavior with respect to null keys and values is same as HashMap.

提交回复
热议问题