tag:blogger.com,1999:blog-8712770457197348465.post5388962816690361023..comments2024-03-19T01:04:48.783-07:00Comments on Javarevisited: How HashMap works in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger142125tag:blogger.com,1999:blog-8712770457197348465.post-80416589880003409632019-07-22T06:21:57.289-07:002019-07-22T06:21:57.289-07:00Hello @Unknown, the bucket location ( index in arr...Hello @Unknown, the bucket location ( index in array) is returned by a hash function, which only return 0 if key is null for other keys it return non-zero index. Also, in worst case, if a collision happens then chaining is used, I mean a linked list is used to store both keys into same location. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-20223932582313479182019-07-20T11:43:21.604-07:002019-07-20T11:43:21.604-07:00Hi,
Can anyone tell me if 0 index in hash table i...Hi, <br />Can anyone tell me if 0 index in hash table is reserved for null key, then what will happen if hash key w.r.t a key in the HashMap is 0. In which index of hash table it will be saved.Debhttps://www.blogger.com/profile/03342077900704958929noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-84089751058906491682019-05-06T13:16:08.086-07:002019-05-06T13:16:08.086-07:00thanks for this helpful guide thanks for this helpful guide Alssamauihttps://www.blogger.com/profile/05306110446025829759noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8263016677188107732018-12-07T04:19:19.378-08:002018-12-07T04:19:19.378-08:00how to generate the hashcode of the object for exa...how to generate the hashcode of the object for example Employee e1=new Employee(). and this is put in map, suppose map.put(e1,"shubhangi"); please tell me how to generate the e1 of hashcodeAnonymoushttps://www.blogger.com/profile/06905150215565752598noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-15942970855364463802018-06-02T19:59:58.326-07:002018-06-02T19:59:58.326-07:00Java now internally replace linked list to a binar...Java now internally replace linked list to a binary true once certain threshold is breached.<br /><br />Kindly correct the spelling mistake . your blog is really good . I have been reading it for many years .roberthttps://www.blogger.com/profile/04117601177930024609noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66586264036350233622018-03-13T07:51:00.270-07:002018-03-13T07:51:00.270-07:00Hi,HashMap is important topic in java, to learn in...Hi,HashMap is important topic in java, to learn in depth about How HashMap works in Java http://beyondcorner.com/hashmap-works-internally/ Anonymoushttps://www.blogger.com/profile/15430265906394667590noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6862337404681484282017-08-09T06:39:43.713-07:002017-08-09T06:39:43.713-07:00Hello @Anonymous, if you read the Javadoc of hashC...Hello @Anonymous, if you read the Javadoc of hashCode method you will get your answer. Hashcode is an integer value which is generated by converting internal memory address of object to an integer. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-13650796655003921862017-08-06T14:37:36.487-07:002017-08-06T14:37:36.487-07:00It is a great article, It really helped me. I have...It is a great article, It really helped me. I have faced one more question in an interview and would like to share with you all.<br /><br />What Hashcode actually represents ? Does it represent memory location of an object or it is just an identifier or its a combination of both the options mentioned ? Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6564606098214968802017-07-19T05:20:51.822-07:002017-07-19T05:20:51.822-07:00@Unknown, good question, but I have never come acr...@Unknown, good question, but I have never come across any good reason with the use of null keys, only practical benefit I see is that it doesn't throw NullPointerExcepiton by calling equals() and hashcode() on null keys. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89157219547913760152017-07-18T12:01:03.806-07:002017-07-18T12:01:03.806-07:00Hashmap allows only one null key.But what is the u...Hashmap allows only one null key.But what is the use of null key in Hashmap?<br />Anonymoushttps://www.blogger.com/profile/00733916595756377109noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75421759845184703492017-03-10T11:49:17.453-08:002017-03-10T11:49:17.453-08:00This article is AMAZING!!! Explained everything so...This article is AMAZING!!! Explained everything so clearly! Nice work!Anonymoushttps://www.blogger.com/profile/07246975732702788206noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-5254936351203731472017-01-25T06:37:41.565-08:002017-01-25T06:37:41.565-08:00"Java now internally replaces linked list wit..."Java now internally replaces linked list with a binary tree once certain threshold is reached."<br />You have so many grammatical mistakes that it's hard to read ...<br />Still a great article, thanks a lotmusclexboyhttps://www.blogger.com/profile/15828809606903759038noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36106967755622386722016-11-28T23:33:37.026-08:002016-11-28T23:33:37.026-08:00@Tappan Patnaik For representing default case.@Tappan Patnaik For representing default case.Swing in the rainhttps://www.blogger.com/profile/05029833523892865293noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-36341924961860845792016-11-12T12:05:31.927-08:002016-11-12T12:05:31.927-08:00Why does one should use null as a key in HashMap?Why does one should use null as a key in HashMap?Anonymoushttps://www.blogger.com/profile/07314862448152349423noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-39774088818980440152016-09-05T05:30:18.002-07:002016-09-05T05:30:18.002-07:00Hi Paul, superb post..especially that diagram.
1) ...Hi Paul, superb post..especially that diagram.<br />1) next variable in Entry object needs more highlight<br />2) If we are putting multiple entries with same keys. Result of get is entry of latest key. But how it work internally.<br /><br />As while putting only hashCode of key is calculated. Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-48552279343382029592016-07-26T01:59:45.822-07:002016-07-26T01:59:45.822-07:00what is the time complexity of insert, delete and ...what is the time complexity of insert, delete and update in hashmap in Java? Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-66682848621903584322016-04-07T04:13:56.252-07:002016-04-07T04:13:56.252-07:00This explanation helps me a lot for interview....This explanation helps me a lot for interview....Anonymoushttps://www.blogger.com/profile/12998130661496147383noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-88916738986997678392016-01-03T20:07:26.900-08:002016-01-03T20:07:26.900-08:00I like your post. You explained it very well.
For ...I like your post. You explained it very well.<br />For those who are not clear on race condition which may cause infinite loop in Hashmap: http://javabypatel.blogspot.in/2016/01/infinite-loop-in-hashmap.htmlAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-65719373320799599822015-07-16T02:07:42.650-07:002015-07-16T02:07:42.650-07:00@Anonymous -
test.size() always returns the actua...@Anonymous - <br />test.size() always returns the actual count of keys held by the HashMap, no matter what is size of the internal table. Size of internal table is always higher than number of entries in the HashMap, and is expanded once number of entries reach certain threshold, which is determined by the load factor. Higher size of internal table provides capacity to accommodate addition of Anonymoushttps://www.blogger.com/profile/06249680252862615440noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-8716867035527335382015-07-02T05:37:52.290-07:002015-07-02T05:37:52.290-07:00Hi,
As per HashMap implementation, HashMap resize...Hi,<br /><br />As per HashMap implementation, HashMap resizes its internal table size when number of elements are >= Load factor * Initial Capacity i.e, 12<br /><br />To test this I debugged below code:<br />public class HashMapTest {<br /><br /> public static void main(final String[] args) {<br /> Map test = new HashMap();<br /> System.out.println("Initial Default Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-65061157325547119682015-06-13T13:47:10.611-07:002015-06-13T13:47:10.611-07:00 race condition in hashmap with picture
http://ma... race condition in hashmap with picture <br />http://mailinator.blogspot.in/2009/06/beautiful-race-condition.htmlVikas Mishrahttps://www.blogger.com/profile/14156666665112079587noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-71741035126252220342015-05-10T23:34:18.777-07:002015-05-10T23:34:18.777-07:00Hi Javin,
Could you please explain how hava 8 use...Hi Javin,<br /><br />Could you please explain how hava 8 uses balanced tree to solve the collision issue.<br />How they will create the balanced tree, as keys has same hash codeThennamnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-78676974511742010562015-04-13T08:53:44.872-07:002015-04-13T08:53:44.872-07:00@Anonymous, null handling is very special, I would...@Anonymous, null handling is very special, I would suggest to check the section about how HashMap handles null keys. To give you answer, multiple null is not an option because HashMap doesn't allow duplicate keys.javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-68957277707525294782015-04-13T07:55:41.609-07:002015-04-13T07:55:41.609-07:00Hi Javin,
This is a nice article. But I have one ...Hi Javin,<br /><br />This is a nice article. But I have one question here <br /><br />Why there is only one null key allowed in Hashmap.Why can't we insert many<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-70814531504301499652015-03-29T10:41:04.130-07:002015-03-29T10:41:04.130-07:00Can you write a similar article on "How treem...Can you write a similar article on "How treemap works using Red Black ago"?Anonymousnoreply@blogger.com