tag:blogger.com,1999:blog-8712770457197348465.post6601295230763242476..comments2024-03-29T03:17:04.645-07:00Comments on Javarevisited: What is difference between HashMap and Hashtable in Java?javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger31125tag:blogger.com,1999:blog-8712770457197348465.post-23988556517707869722018-01-07T11:44:17.095-08:002018-01-07T11:44:17.095-08:00Very useful article.
One thing want to mention, i...Very useful article.<br /><br />One thing want to mention, image which you have given for comparison(for synchronization) in that it should be Collections but its Collection in the image.Mukulhttps://www.blogger.com/profile/01111830793909968117noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-51986020255445750802017-01-25T07:05:58.409-08:002017-01-25T07:05:58.409-08:00As some other person has already mentioned you are...As some other person has already mentioned you are describing differences between fail-safe and fail-fast wrong in this article. Fail-fast means throwing ConcurrentModificationExceptionmusclexboyhttps://www.blogger.com/profile/15828809606903759038noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36789166812966415412016-06-04T21:32:56.313-07:002016-06-04T21:32:56.313-07:00I am having a problem grasping that remove()is O(1...I am having a problem grasping that remove()is O(1)in both the Hashset and LinkedHashset. I understand that the remove() for a hashset is O(1) ut in a linkedhashset, my understanding is that it is o(1) to determine that the Object is in the set and then o(n)to search for the order that the object was added which is o(n).<br />JBondhttps://www.blogger.com/profile/04287112816699182102noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-85127376826340550672016-04-11T20:41:10.212-07:002016-04-11T20:41:10.212-07:00Hi Javin,
I gotta bit of confusion between enumer...Hi Javin,<br /><br />I gotta bit of confusion between enumeration and iterator, few folks on the internet mentioning Enumeration is not fail-safe. But actually when i tried to do structural changes to hashtable, it simply allowed the changes to be made without any error just like CHM. Can you please explain me why?Swing in the rainhttps://www.blogger.com/profile/05029833523892865293noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-35703103145886357422015-10-30T21:54:55.108-07:002015-10-30T21:54:55.108-07:00@Anonymous, if you are looking for some good examp...@Anonymous, if you are looking for some good examples on HashMap then I suggest you to take a look at this tutorial, <a href="http://java67.blogspot.com/2013/02/10-examples-of-hashmap-in-java-programming-tutorial.html" rel="nofollow">10 examples of HashMap in Java</a>. It's a great guide about using HashMap, particularly for anyone like you who wants to know more about HashMap.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-38627495081082918952015-10-28T01:10:10.340-07:002015-10-28T01:10:10.340-07:00hi everyone,
I am starting to learn about java but...hi everyone,<br />I am starting to learn about java but I need to know about a HashMap in java, actually, this is problem difficult because If you want to understand anything i think we should test program. It's help have look good better. I think I will remember best. So thanks a lot, I am try read all comment of friends in here. It's great for me.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66033528766373428112015-09-15T22:23:37.182-07:002015-09-15T22:23:37.182-07:00Hello
@Javin, If Enumeration doesn't throw th...Hello <br />@Javin, If Enumeration doesn't throw that exception then it will update the concurrent modification? or prevent it? what it will do.. Please explain..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12752185626108316792015-08-15T08:46:44.801-07:002015-08-15T08:46:44.801-07:00@makam, actually that true, Iterator of HashMap th...@makam, actually that true, Iterator of HashMap throws ConcurrentModificationException when HashMap is modified after iteration begun but Enumeration doesn't throw that exception.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7353195649271867602015-08-10T11:11:09.317-07:002015-08-10T11:11:09.317-07:00I think that this phrase is wrong,
"3. Anot...I think that this phrase is wrong, <br /><br />"3. Another significant difference between HashMap vs Hashtable is that Iterator in the HashMap is a fail-fast iterator while the enumerator for the Hashtable is not and throw ConcurrentModificationException ... "<br /><br />So if the enumerator is not fail-fast, is fail-safe, and will not thrown an exception, right? maybe I'm missingmakamhttps://www.blogger.com/profile/13354458741659446795noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-40179194073892660712014-11-28T23:39:00.853-08:002014-11-28T23:39:00.853-08:00There are several differences between HashMap and ...There are several differences between HashMap and Hashtable in Java:<br /><br /> Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.<br /><br /> Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.<br /><br /> One SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-33672101139700869792014-11-18T08:11:00.899-08:002014-11-18T08:11:00.899-08:00In a web application can we use HashMap. instead o...In a web application can we use HashMap. instead of HashTable.<br />If the answer is HashMap. then How?<br />In an webapplication are there not multiple thread trying to access the servlet or the EJB? How is it safe to use HashMap?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-1342320465394720132014-08-13T06:22:17.968-07:002014-08-13T06:22:17.968-07:00hash map allows null as values in key which is not...hash map allows null as values in key which is not true in case of hash table. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-49358005261626589302014-07-16T10:19:31.341-07:002014-07-16T10:19:31.341-07:00Hi,
what is the difference between synchronized h...Hi,<br /><br />what is the difference between synchronized hash-map and hash table?<br /><br />I don't see any difference here but interviewer asked this quest ion.Can some one please explain me?<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-18353973379042975652013-12-15T19:35:25.257-08:002013-12-15T19:35:25.257-08:00Hi
For getting the synchronized map the method na...Hi<br /><br />For getting the synchronized map the method name is collections.synchronizedMap() not synchronizeMap()Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72349318684123381932012-12-19T02:37:18.636-08:002012-12-19T02:37:18.636-08:00Hi
We can synchronize Map object using Collection...Hi<br /><br />We can synchronize Map object using Collections.synchronizedMap(mapObj)...<br /><br />Then <br /><br />1) what is difference for map object(after synchronize using synchronizedMap method) and hashtable object?<br /><br />2) Will be there any difference in synchronization using the method and by default the class as synchronized..Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66620645901939935772012-09-27T19:50:42.853-07:002012-09-27T19:50:42.853-07:00Can you please put a feature and performance compa...Can you please put a feature and performance comparison between <br />1. HashMap vs ConcurrentHashMap <br />2. HashMap vs Hashtable<br />3. HashMap vs LinkedHashMap<br />4. Hashtable vs ConcurrentHashMap<br />5. Hashtable vs LinkedHashMap and<br />6. ConcurrentHashMap vs LinkedHashMap<br />that would be simply great. Also if you could share when to use Hashtable, HashMap, ConcurrentHashMap and Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-28843231222216990962012-08-02T11:46:05.573-07:002012-08-02T11:46:05.573-07:00So it was it Hashtable() instead of HashTable() or...So it was it Hashtable() instead of HashTable() or something...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-21354438400531567102012-01-29T21:12:40.874-08:002012-01-29T21:12:40.874-08:00from Java4 I guest hashtable is also part of colle...from Java4 I guest hashtable is also part of collection framework along with Vector. with the age of ConcurrentHashMap, does Hashtable still holds value ?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-10882234675526731792012-01-20T20:03:37.964-08:002012-01-20T20:03:37.964-08:00iterator can be implemented for hashtable alsoiterator can be implemented for hashtable alsoAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2101438563448635232011-12-29T04:12:25.190-08:002011-12-29T04:12:25.190-08:00Thanks Nagesh for your comment and good to know th...Thanks Nagesh for your comment and good to know that you like this hashtable vs hashmap tutorial. you may also like <a href="http://javarevisited.blogspot.com/2011/09/difference-vector-vs-arraylist-in-java.html" rel="nofollow">Difference between ArrayList and Vector in java</a>Javin @ spring interview questions answershttp://javarevisited.blogspot.com/2011/09/spring-interview-questions-answers-j2ee.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75298848518407368002011-11-27T20:19:07.542-08:002011-11-27T20:19:07.542-08:00correct, though both hashtable and hashmap are old...correct, though both hashtable and hashmap are older than new concurrenthashmap iterator and enumeration is key point.I would suggest to leave behind both hashmap and hashtable and move forward to concurrenthashMap.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22662648906608795792011-09-08T02:05:41.063-07:002011-09-08T02:05:41.063-07:00I think key difference between hashmap and hastabl...I think key difference between hashmap and hastable is what you mentioned about Iterator and Enumeration , as Iterator being fail-fast beccomes natural choice over enumeration.Neerjanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41293772002519158442011-07-27T20:41:29.295-07:002011-07-27T20:41:29.295-07:00wow Anonymous got more differences between hashtab...wow Anonymous got more differences between hashtable and hashmap :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-82248669509964477282011-07-12T00:10:04.227-07:002011-07-12T00:10:04.227-07:00here are some more differences between hashtable a...here are some more differences between hashtable and hashmap<br /><br />1) hashtable extends Dictionary interface which is quite old while hashmap extends Map interface.<br />2) hashtalbe doesn't have counterpart like ConcurrentHashMap.<br />3) another important difference between hashtable and hashmap is , hashtable is less secure than hashmap because of Enumeration it uses. while hashmap Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-13395514789684399992011-07-09T20:44:52.802-07:002011-07-09T20:44:52.802-07:00Hi Anonymous fail-fast iterator means if one thre...Hi Anonymous fail-fast iterator means if one thread is iterating over hashmap and other thread trying to modify hashmap structurally it will throw ConcurrentModification Exception and fail immediately while in fail-safe iterator Iterations is done on copy of collection object instead of original e.g. in case of CopyOnWriteArraylist. iterator of hashmap is fail-fast and hashtable doesn't haveJavinnoreply@blogger.com