tag:blogger.com,1999:blog-694855878384792308.post1934016092696105229..comments2024-03-21T06:26:49.387-07:00Comments on Java67: 5 Difference between Hashtable vs HashMap in Java? Answerjavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger28125tag:blogger.com,1999:blog-694855878384792308.post-20211621008256195292021-01-15T05:08:22.480-08:002021-01-15T05:08:22.480-08:00I don't think Hashtable allows null keys as we...I don't think Hashtable allows null keys as well. May need to double check. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-65838782943335877842021-01-14T11:02:43.616-08:002021-01-14T11:02:43.616-08:00Awesome Awesome Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-37187709218834669712018-06-21T23:12:30.253-07:002018-06-21T23:12:30.253-07:00HashMap allow one null key and multiple null value...HashMap allow one null key and multiple null values where as hashtable does't allow null values.Anonymoushttps://www.blogger.com/profile/03937123881096407397noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-34697488914835152882018-04-21T22:44:56.282-07:002018-04-21T22:44:56.282-07:00If we take HashMap it is not thread safe but want ...If we take HashMap it is not thread safe but want Thread safe means we need to go SynchronizedHashMapAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-40836054741104412092018-02-06T04:58:55.118-08:002018-02-06T04:58:55.118-08:00entry with null key always stored at index = 0entry with null key always stored at index = 0Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-71819021259816040102017-06-17T19:46:15.840-07:002017-06-17T19:46:15.840-07:00True, Hashtable is present from JDK 1.0 but HashMa...True, Hashtable is present from JDK 1.0 but HashMap was later added on Java 1.4 javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-26112789951021213482017-06-17T19:45:47.153-07:002017-06-17T19:45:47.153-07:00@Nargendara, good point. Interviewer will then ask...@Nargendara, good point. Interviewer will then ask you how does HashMap resolve value for null key? remember, you cannot call equals() or hashcode() on null :-)javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-64949745082625826492017-06-17T08:09:34.865-07:002017-06-17T08:09:34.865-07:00HashTable is legacy class whereas HashMap was adap...HashTable is legacy class whereas HashMap was adapted later in JavaAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-87033632765456829442016-08-10T18:42:49.948-07:002016-08-10T18:42:49.948-07:00HashMap allows one null key and multiple null valu...HashMap allows one null key and multiple null values where as <br />Hashtable not allows any null keys and null values.Anonymoushttps://www.blogger.com/profile/03390897862105145823noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-6706420293238700012016-07-08T01:15:38.636-07:002016-07-08T01:15:38.636-07:00Hashtable is a legacy class and present from JDK 1...Hashtable is a legacy class and present from JDK 1, HashMap was added laterDushmantahttps://www.blogger.com/profile/11235032746336638916noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-1351346360453163542016-06-21T05:26:34.198-07:002016-06-21T05:26:34.198-07:00@Anonmous, absolutely correct, btw, do you know wh...@Anonmous, absolutely correct, btw, do you know why Hashtable doesn't allow null keys?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-43149257004514493182016-06-21T00:42:56.320-07:002016-06-21T00:42:56.320-07:00HashMap allows a null key multiple null values whe...HashMap allows a null key multiple null values whereas hashtable neither allows null key nor values.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-17079931937256230362015-08-30T03:58:08.445-07:002015-08-30T03:58:08.445-07:00Yes, that's true. Hashtable did extends Dictio...Yes, that's true. Hashtable did extends Dictionary class but it also implement Map interface. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-4117346908271075502015-08-29T07:51:24.339-07:002015-08-29T07:51:24.339-07:00HashMap class extends AbstractMap, whereas Hashtab...HashMap class extends AbstractMap, whereas Hashtable extends the obsolete class Dictionary.<br /><br />and the popular class Properties extends Hashtable class neither HashMap nor ConcurrentHashMapaaaaa bbbbbhttps://www.blogger.com/profile/18155192310348703093noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-59439243333618348722015-07-02T12:57:48.165-07:002015-07-02T12:57:48.165-07:00Initial capacity of hashtable is 11 while it is 16...Initial capacity of hashtable is 11 while it is 16 in case of hashmap..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-21781393364739657452015-06-18T05:25:52.892-07:002015-06-18T05:25:52.892-07:00hashtable not allowed any null keys or any null va...hashtable not allowed any null keys or any null value where as hashmap can have oe null key and any more null values..Anonymoushttps://www.blogger.com/profile/07273542621370142523noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-28747545724931657082014-07-16T10:04:28.955-07:002014-07-16T10:04:28.955-07:00Yes.Yes.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-62989021290202577632014-05-13T12:06:39.077-07:002014-05-13T12:06:39.077-07:00cooll...cooll...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-9096282063853291652014-02-25T07:54:33.159-08:002014-02-25T07:54:33.159-08:00HashMap permits one null key and multiple null val...HashMap permits one null key and multiple null values.<br />Hashtable doesn't permit any sort of nulls (key or values).Rahul Shuklahttps://www.blogger.com/profile/10759976262648241582noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-50888183203720618302013-10-27T07:56:42.621-07:002013-10-27T07:56:42.621-07:00Hi Anonymous HashMap is faster than HashTable -- H...Hi Anonymous HashMap is faster than HashTable -- HashMap is unsynchronized while hash table is synchronizedAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-68417527387276523382013-08-02T03:50:48.850-07:002013-08-02T03:50:48.850-07:00plus HashMap is slower than Hashtable because of t...plus HashMap is slower than Hashtable because of the synchronoization factor.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-10619696710000904392013-05-23T08:39:23.843-07:002013-05-23T08:39:23.843-07:00 why hashtable not allowed any null keys or any nu... why hashtable not allowed any null keys or any null value where as hashmap can have oe null key and any more null values.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-42689476713430068462013-05-22T17:18:47.556-07:002013-05-22T17:18:47.556-07:00Hash table maintains order over a constant period ...Hash table maintains order over a constant period of time whereas hash map doesnot mantian order Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-70060077867747603832013-05-06T22:40:50.455-07:002013-05-06T22:40:50.455-07:00Nice ,
But if given the thread safe example then i...Nice ,<br />But if given the thread safe example then it would be better to understand.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-30518622456768948742013-02-12T18:32:29.316-08:002013-02-12T18:32:29.316-08:00one common diff also is that hashtable not allowed...one common diff also is that hashtable not allowed any null keys or any null value where as hashmap can have oe null key and any more null values..Anil Mehrotrahttps://www.blogger.com/profile/07350125133794525688noreply@blogger.com