tag:blogger.com,1999:blog-8712770457197348465.post8512549479248611419..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: Difference between HashMap and HashSet in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-8712770457197348465.post-39266107508584464822018-03-13T05:54:32.356-07:002018-03-13T05:54:32.356-07:00From the implementation of HashSet class, we can s...From the implementation of HashSet class, we can say that it internally stores the objects into HashMap into keys with a dummy object.<br /><br />public class HashSet<br />extends AbstractSet<br />implements Set, Cloneable, java.io.Serializable<br /><br />{<br /> private transient HashMap map;<br /> // Dummy value to associate with an Object in the backing Map<br /> private static final Sanjeev Kulkarnihttps://www.blogger.com/profile/06563572460400054503noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12877941903697911922016-07-11T08:32:55.657-07:002016-07-11T08:32:55.657-07:00@Unknown, sure, will add some examples sooner. @Unknown, sure, will add some examples sooner. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-59429187295227724152016-07-09T04:25:35.126-07:002016-07-09T04:25:35.126-07:00Please add also examples.Please add also examples.Anonymoushttps://www.blogger.com/profile/08403939452548555656noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48922252159073592092016-04-08T22:59:30.583-07:002016-04-08T22:59:30.583-07:00Nice explanation Nice explanation Kunalhttps://www.blogger.com/profile/01071139322481518816noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-14936720050398493432014-07-25T01:30:34.611-07:002014-07-25T01:30:34.611-07:00how hashmap works internally in java? could u plea...how hashmap works internally in java? could u please explain in detailAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-9624708211799757752013-08-13T03:20:58.618-07:002013-08-13T03:20:58.618-07:001. When Hashset is just a wrapper which uses HashM...1. When Hashset is just a wrapper which uses HashMap, How is it slower than HashMap? <br />2. When both classes do not have the same methods, how was this performance comparison done (Again add method of HashSet only delegates the call to a internal HashMap's put method)?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-46280090761513939842013-06-14T05:35:07.129-07:002013-06-14T05:35:07.129-07:00your articles are awesome..easy to understand.
Is ...your articles are awesome..easy to understand.<br />Is there an article where you explain how hashset is implemented using a hashmap?<br />Also what is the internal working of hashmap, like it is a combination of array and linked list or what actually is a bucket, Map.Entry and all??<br />Can you please provide me the links to such articles?saytidahttps://www.blogger.com/profile/16904955270370642982noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48800382646195224132013-03-14T23:03:31.867-07:002013-03-14T23:03:31.867-07:001. Because HashSet does not implement Map interfac...1. Because HashSet does not implement Map interface and Set interface does not declare get() method.<br />And there is no key, that you can pass to get() method in case of a set (since all keys are values). If you need to check that specified key exists in the set just use contains() method.<br />2. It should not be slower, because HashMap does not allow duplicated keys as well. So, performance Anonymoushttps://www.blogger.com/profile/01093770973064557805noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-7776774218961349322013-02-28T21:07:49.776-08:002013-02-28T21:07:49.776-08:00What is the underlying implementation behind HASH ...What is the underlying implementation behind HASH SET & HASH MAP--- the same concept of key value pair, now how can HASH MAP is faster than HASH SET when conceptual implementation behind both collection is same?Anonymoushttps://www.blogger.com/profile/11727197663235393142noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72669350162973279322013-02-23T22:18:11.472-08:002013-02-23T22:18:11.472-08:00As we know that HashSet is the wrapper on the Hash...As we know that HashSet is the wrapper on the HashMap to implement unique set i have below 2 questions<br /><br />1. why HashSet does not support get() method like the HashMap?<br /><br />2. Why HashSet is slower than HashMap?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24947610851484208682013-02-10T03:12:32.739-08:002013-02-10T03:12:32.739-08:00So there is no concept of key object in HashSet.
A...So there is no concept of key object in HashSet.<br />Am i right?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-87233769550225768982012-08-02T07:43:13.046-07:002012-08-02T07:43:13.046-07:00Please share your view on Vector Vs synchronized(a...Please share your view on Vector Vs synchronized(arrayList)nitusnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-39670883982786902722012-08-01T23:59:36.849-07:002012-08-01T23:59:36.849-07:00HashSet internally uses HashMap to store Objects.O...HashSet internally uses HashMap to store Objects.Objects are stored as a key in HashMap and a new dummy Object is placed as value.Since Hashmap does not allow duplicate key,HashSet maintains its uniqueness.nitusnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-47139292868654795682012-06-22T20:23:02.920-07:002012-06-22T20:23:02.920-07:00Another difference between HashMap vs HashSet is t...Another difference between HashMap vs HashSet is that HashMap uses put() method while HashSet uses add() method. HashMap requires two object as key and value , while HashSet only need one object to store. Overall HashSet vs HashMap is comparison between Map and Set Collection type in java.Vickynoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-12793434314166674152012-05-07T07:41:18.378-07:002012-05-07T07:41:18.378-07:00You made a good point, but the explanation is horr...You made a good point, but the explanation is horrible!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68115752477787540462011-10-01T19:45:57.482-07:002011-10-01T19:45:57.482-07:00Yes you are correct, hashcode is used to find the ...Yes you are correct, hashcode is used to find the bucket location and then while comparing object it uses equals in place of hashcode. you can read more on this on <a href="http://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html" rel="nofollow">How HashMap works in Java</a>Javin @ java enum exampleshttp://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-83495484074732394462011-10-01T05:56:49.172-07:002011-10-01T05:56:49.172-07:00hashCode can be the same for 2 keys in a HashMap s...hashCode can be the same for 2 keys in a HashMap so HashMap uses equals.<br /><br />In Oracle's Java implementation HashSet is only a wrapper around a HashMap.jamesnoreply@blogger.com