For anyone confused about how the index value is calculated: the “&” operator is a “bitwise AND” operator. When it is used, both its operands (the numbers before and after the operator) are converted to binary, and a bitwise “and” is performed on each pair of matching place values in both binary numbers. This results in a new binary number. For example: 12 & 5 = 4, since 1100 & 0101 = 0100 And also 2306996 & 15 = 4, since 1000110011001110110100 & 0000000000000000001111 = 0000000000000000000100
@coding_ss6325 жыл бұрын
Thanks Rick
@MuzicalMelody4 жыл бұрын
How to get the hash value
@yaruiwu74084 жыл бұрын
This is just wonderful
@balajikoc14294 жыл бұрын
Thanks Rick
@adarsh67504 жыл бұрын
Thanks rick
@manishsoni76893 жыл бұрын
I think I will add one more point at 7:50, When you call put() for the element having the same index or hashcode() it calls equals() method as well to compare the key. If it's same then it will overwrite the previous element and if not then append to the next node. This part is very important because once I was asked what will happen if you only implement hashcode() and not equals() or vice versa.
@mohsensm74383 жыл бұрын
This point is very necessary to complete this good video.
@PavanKumar-yj8fu3 жыл бұрын
Very good point, thanks
@ArkAngelHFB2 жыл бұрын
Would this mean that without the equals() method call, a HashMap could erroneously overwrite both Key and Value at the same time?
@dmitrikonnov9222 жыл бұрын
@@ArkAngelHFB no, it doesn't make sense to overwrite the key, because its already in the array. Instead, the value is overwritten, because the hashmap doesn't tolerate duplicates. This can be also tricky when we deal with children nodes, for instance with one-to-many relationship. Sometimes one's better of to override children's hashcode() based on their class only, so that all children (objects of the same class) have the same hash code.
@ArkAngelHFB2 жыл бұрын
@@dmitrikonnov922 But without the equals() call, wouldn't it just assume that since it shared the same hash, it WAS the same key and overwrite it?
@sent2anil8 жыл бұрын
This is the best tutorial I found for "How HashMap works"! Demo using animation is remarkable :)
@madhugali9 жыл бұрын
I'd like to add a point to the wonderful explanation of HashMap implementation When HashMap reaches its threshold limit of .75 or 75% it re-size by creating a new array of double the previous size HashMap, and then start putting every old element into that new bucket array and this is called rehashing and it also applies hash function to find new bucket location.
@satishpatil1156 жыл бұрын
for any object the index will be 0 to (n-1) when we take mod of (n-1), then why we need to re-index or it re-sizes ???
@ayushjindal49816 жыл бұрын
we need to do it so that get and put operations can be done in O(1). if we dont do it, the size of linked lists would keep on increasing and would eventually increase the cost of operations.
@vishalkumargupta79866 жыл бұрын
It does not take double size but size equal to next power of 2.
@v0nnyboy6 жыл бұрын
You're implicitly stating that it's double ... as a previous power of 2 ( 2^4) is being multiplied by 2 .
@ayushman_sr6 жыл бұрын
this was important part... yet nit covered
@shyamalmunshi8 жыл бұрын
This is probably the best explanation of Hashmap I've come across! Kudos to you!
@anuraag31037 жыл бұрын
This is the best explanation available in youtube for Hashmap...!!
@condor10168 жыл бұрын
This HAS to be one of the finest tutorials I have ever seen. The use of the animation was extremely well thought out and makes the subject so clear even a non-developer should understand it! Very well done! Thanks for your efforts Ranjith.
@barrettkepler76182 жыл бұрын
HashMaps finally demystified. Thank you very much
@VinodKumar-ng3kc5 жыл бұрын
People who has disliked, what are you guys expecting ? This is just perfect explanation!!
@javatmz5 жыл бұрын
:) right
@jackfarah74942 жыл бұрын
my friend, I wish i saw this 3 days ago.... I didnt learn anything new because I have been studying hashMaps pretty aggressively the last 3 days, but my life would have been A BILLION TIMES BETTER if i found your video first. Beautifully detailed and easy to understand! TO BEGINNERS, THIS IS THE BEST INTRO TO HASHMAP VIDEO ON KZbin!
@areyoucerealtube8 жыл бұрын
Right on my dude. I've been struggling with one specific piece of the implementation (what we do with the hash code), but this video explains it perfectly. Thank you!!
@sandeepsingh-de4fg4 жыл бұрын
Great explanation. If anybody want to know how HashMap internally works please watch this video once. Thanks for sharing such amazing video.
@nabinsaud46564 жыл бұрын
Holy shit I was confused about hash tables for so long and this video simplified in such a nice way.
@nishikanttayade74466 жыл бұрын
this is THE BEST EXPLANATION of HashMap...thanks
@ranjithramachandran59289 жыл бұрын
HashMap working animation + enhancements for HashMap in Java8 - check out! If you liked, please leave a comment!
@chilltouchng9 жыл бұрын
+Ranjith ramachandran Really good! This is the best tutorial about "How HashMap works"!
@ChandrakanthReddySoodiReddy8 жыл бұрын
Very Helpful video on HashMaps. I actually understood how Look up works. Thank you...
@atulkumar-hm6yo8 жыл бұрын
Sir,Please share how Hashcode made...!!!!
@satyaprakashnayak13637 жыл бұрын
Very wonderful tutorial....Can you please also explain in animation How ConcurrentHashMap and ConcurrentLinkedQueue works?
@kinjalthehero7 жыл бұрын
Thank you
@sivakrishnat54713 жыл бұрын
hands down this is the best video on how hashmap works internally. Thank you very much.
@saruncse857 жыл бұрын
I was looking for a good explanation for a long time, and I found today. Thanks, Ranjith.
@gagangupta12553 жыл бұрын
One of the best resource on HashMap. Really stunning !!!
@SagarAnkitaUpdates4 жыл бұрын
This is the best video that I have seen by now, however its sad that you have stopped posting now
@rajendrakumar20114 жыл бұрын
Excellent explanation with example of how hashmap put and get method works internally.
@RagPeddabudi9 жыл бұрын
this is awesome explanation dude.. The best one for HashMap
@ginny59674 жыл бұрын
😭
@ginny59674 жыл бұрын
R
@RagPeddabudi4 жыл бұрын
@@ginny5967 watzup buddy ?
@RagPeddabudi4 жыл бұрын
@@ginny5967 wat made u cry
@benjaminsinanovic41233 жыл бұрын
Best explanation from all videos I looked on yt.
@naveedhassan73994 жыл бұрын
Great explanation. The only point I feel missed was when two keys have the same hashcode the Node actually overrides the original nodes and doesn't get appended to the Linked list. Your run case could have included this scenario.
@jasper50163 жыл бұрын
Good one brother
@vyshnavramesh9305 Жыл бұрын
both hashcode() and equals()
@irynasherepot98824 жыл бұрын
Wow, this is the best tutorial about itHashMap on KZbin!
@yuyuejiang32788 жыл бұрын
This is an in-depth very well explained video! Thanks a lot!
@ranjithramachandran59288 жыл бұрын
Thanks!
@arvind1431004 жыл бұрын
@@ranjithramachandran5928 Hi, Sir, I have a doubt, kindly explain plz. My "Eclipse IDE" showing two hash value for key "apple" (and for others key too), i.e, 93029210(index = 10) and 93030097(index = 1). According to formula it should be index=10, but it is placed at index= 1. Kindly, explain why we get two hash value for each key, and why its index is 1 and not 10. 🙏🙏🙏
@komirellykasanaboina55974 жыл бұрын
@@ranjithramachandran5928Hi sir Nice Explanation and I have a small doubt, could you please explain once,In MAP, If two Entries having same key and same hashcode?? HashMap map=new HashMap(); map.put("101","hdfc"); System.out.println(map.put("101","sbi")); //Returning value is = hdfc //After iterating Map, and getValue() method returning = sbi Could you please explain why it's print 'sbi'', How about hashcode and equals method work in this case????
@techiebrat94983 жыл бұрын
Awesome explanation .thanks a ton.
@RiteshPuj9 жыл бұрын
I learned a lot about Hashmap from this video. Thanks a lot Ranjith, you have did a great job. :)
This is just crystal clear explanation!! The best explanation for hashMap!!! And thank you for the information about the updated hashMap in Java 8. That's so cooool and smart!!
@harshavardhan78 жыл бұрын
Dude more videos please :) You are awesome :)
@chaitanyaasati3 жыл бұрын
Amazing explaination and animation!! Love it.
@shadabsheikh518 жыл бұрын
Hey Ranjith Very detailed and nicely animated work..It was easy to understand
@Jithu00134 жыл бұрын
Best video i have ever found in you tube regarding implementation of hash map .Described it clearly
@daikhostephen72886 жыл бұрын
Correction: Whenever there is collision, the new entry should added as the head of linked list, not tail.
@sameer_sah4 жыл бұрын
any references ?
@sergeyvechkitov2214 жыл бұрын
p.next = newNode(hash, key, value, null);
@bsaikumarreddy14133 жыл бұрын
Yes. Because the insertion will take O(1) time by inserting at head rather than tail.
@cathynest4593 жыл бұрын
This is the best explanation so far
@vincentkimt8 жыл бұрын
Hi Ranjith, In the first put operation scores.put("KING",100). your index comes to 4. But according to index = hash % (n-1) it should be index = 2306996 % (16-1) this gives 11 and you calculated it as 4. However, if we put 'n' instead of 'n-1' we will get result as 4. So either the formula hash % (n-1) needs to be changed to hash % (n), if you are calculating indexes correctly or if the formula is already correct, your index must come out to be 11. need your comment on this. thanks
@ranjithramachandran59288 жыл бұрын
+Vincent Lal Please note the index is calculated as hash & (n-1) which is same as hash % n-1
@raju50817 жыл бұрын
it should be n only as the operation always outputs 0 to 15 which are indexes of the table 0 to 15.
@_Vaibs_7 жыл бұрын
+Vincent Lal Wondering how you can calculate like that. Do it bitwise . 2306996=1000110011001110110100 , (n-1)=(16-1)=15= 1111 , 1000110011001110110100 AND 1111 = 0100 which in decimal is 4.
@gnanasekaranebinezar71996 жыл бұрын
Splendid explanation with Animation. I have been using HashMap more than decade. Now, I got clarity how it works internally. Thanks for the commendable work!!!👏
@chaitu20379 жыл бұрын
Good explanation, but can you remove the recording of yourself, frankly it is a little disturbing to watch your head tilt frequently.
@rhimanshu62887 жыл бұрын
true
@nirmitsrivastava7 жыл бұрын
true
@rexroy40377 жыл бұрын
yes its kind of disturbing ..
@shubhamsrivastava54007 жыл бұрын
lol
@ahmetemreboyaci7 жыл бұрын
well that's ungrateful
@sonammittal67235 жыл бұрын
Best tutorial for understanding HashMap. Thanks a lot !
@yogeshvbk9 жыл бұрын
How hash(k) is calculated? Can you please explain..
@ranjithramachandran59288 жыл бұрын
+Yogesh Bhat - hash(k) in real implementation is done to address "poorly" implemented hashcode methods in classes, that will cause a bucket(or index) loaded with too many nodes(or in older terms entries). It basically spreads higher bits of actual hashcode to lower order. This is done because the modulo operation produces different results only based on lower order btis.(in base 10, think of numbers at 'ones' position)
@roxanamoghbel91473 жыл бұрын
this is the best explanation on the internet
@atulyadav21j7 жыл бұрын
During put operation, why did we need to compare the hashcode, only comparing the keys will work. Say for an instance two keys have a same hashcode, in that case comparing with hashcode takes you no where, you have to compare key. May be I am missing something, please correct me I am going somewhere wrong.
@etofok7 жыл бұрын
keys are objects, you'll need to run .equals(). integers are much faster to compare via "&"
@skullwise6 жыл бұрын
I had asked the same question. :-)
@AmbujRajput6 жыл бұрын
One of the best explanation of HashMap
@jonkc36358 жыл бұрын
Your face is in the way of the slides. lol
@ssbabu788 жыл бұрын
Great and useful information with clear explanation and awesome animation. Thank you.
@sangitdhanani21379 жыл бұрын
dude stop coming back and forth in to the screen. Its distracting
@dhirajchandra778 Жыл бұрын
very lucid way to present the explanation, awesome, thanks alot.
@robertsahayakumar52673 жыл бұрын
Ranjith, You have Awesome teaching skill. Without any doubt , This is the best explanation of Hashmap . I experienced the same ease of my understanding regarding your garbage collection in Java explanation too. Cool.
@shikher123yo9 жыл бұрын
perfect video to learn how hashmap works in a very short time.
@djethrak45672 жыл бұрын
Best explanation I have seen so far
@vaibhavjain36106 жыл бұрын
The best explanation for hashmap internal working. Thanks man.
@mathisinav42674 жыл бұрын
Excellent, the animation is Outstanding, great job
@ArdhenduShekharSingh15088 жыл бұрын
Thanks Ranjith for tutorial. After referring to tutorial I visited the actual source code of Hashmap and now its pretty much clear about the functioning of put and get method and also about resizing of the table size when it reaches the threshold.
@uzoamakamadueke71013 жыл бұрын
This is the tutorial on hashmap I have been searching for...great job...very well explained...thank you
@ke30_2 жыл бұрын
Ty so much this is a great explanation
@ronak2127 жыл бұрын
This got to be the best explanation of Internal working of hasmap that I have ever seen. Thanks..!
@rajajodhani2 жыл бұрын
So helpful and explained in a very simple way
@stark4695 жыл бұрын
Now i have got the detailed knowledge of hashmap.... Thanks
@tolibisql5 ай бұрын
Best explanation. Perfect
@reenalparmar5407 жыл бұрын
Very Good Explanation for Hashmap implementation..Thank you...
@vibhorhadke9888 жыл бұрын
Ranjith with the animation it's very easy to understand Internal functionality .Great effort and Thanks
@satyajeetkumarjha14822 жыл бұрын
Really good explanation with the help of animation.
@AbhijitDixit-ki1oo10 ай бұрын
Use of animation really helps understand the concept. Thank you so much sir 🙏
@dmytromelnychuk19099 жыл бұрын
Its the best video about HashMap!
@swamik59354 жыл бұрын
Very well explanation of HashMap .
@amansrivastav96916 жыл бұрын
One of the genuine and worthy explanation.
@KZwai6 жыл бұрын
The best! ...and I knew nothing about this complex topic before the video, but now it's my favorite, thank you!
@ravisahu33958 жыл бұрын
Great explanation about hashing and collisions...
@SeekerofYab8 жыл бұрын
You've made this really easy to understand, and your animations are super-helpful. Thanks!
@ranjithramachandran59288 жыл бұрын
+raszelast thanks!
@maximshen30788 жыл бұрын
Best HashMap explanation and animation !
@rs62627 жыл бұрын
Nice presentation with animation. Thank you...
@pravinghorpade27719 жыл бұрын
Very Good explanation and Animation...Thanks
@radhikagadve Жыл бұрын
there cannot be a better explanation than this... thanks :)
@MrAsgar1234 жыл бұрын
Awesome Explanation , now i got the clear idea of how HashMap internally works, thanks a lot.
@dillipkumarnayak7867 жыл бұрын
Very Nice explanations Sir thanks a lot... for sharing
@pushpal.r.10962 жыл бұрын
Very nice explanation. Thank you Sir.
@shuvenduoffline2 жыл бұрын
Nicely explained! Thanks, keep creating !!
@indurana18352 жыл бұрын
Earlier i though it would be very complicated concept but sir you made it so simple. thanks
@pankajk29287 жыл бұрын
This is the best explanation for HashMap. Thanks Ranjith.
@ziqic30194 жыл бұрын
Thanks for the well explained HashMap
@MikeAetherial9 жыл бұрын
This is the first explanation that has made sense to me! Its like an epiphany! Thank you!
@bikaspatro33299 жыл бұрын
Excellent demonstration of HashMap implementation!!
@NileshPatil-m9l4 ай бұрын
Your videos are very thoughtful and to the point You should start making more of such content - Watching this in 2014
@MadhuCM9 жыл бұрын
Excellent explanation with animation. great going and thanks.
@arvindaggarwal8 жыл бұрын
Quite awesome..... presentation with nice crystal-clear language.....so nice....so much helpful.....I was so confused from last 4-5 years.....but today its remove all deadlocks of confusions and misunderstanding about hashmap's Internals......
@abhilashreddy38534 жыл бұрын
Thanks for a clear explanation with visuals.
@AmitKumar-qh4ow9 жыл бұрын
Excellent Video on HashMap
@neetishraj7 жыл бұрын
Thank you Ranjith, you strike right into the root concepts that clear all doubts that branch out from that root confusion. Thank you sir
@TheN0odles8 жыл бұрын
Excellent. Thanks for posting.
@72seenu8 жыл бұрын
Very nice explanation Thank you so much .
@bavanasudheerkumar8 жыл бұрын
Very clear explanation,good that you discussed the enhancements for hashmap in Java 8.
@araveetivenkatesh69426 жыл бұрын
Very good explanation.thanku somuch
@mollamainuddin64853 жыл бұрын
awsome tutorial.....thank you very much
@jathitu8 жыл бұрын
Superb video explaining HashMap. Best i have gone through for any topic on Java. Please post more videos, would love to hear on many more Java topics from you.
@AshishBurnwal7 жыл бұрын
Best explanation till date... Thanks a lot
@momodoufatty33156 жыл бұрын
Amazing tutorial. Super easy to understand. Thanks.
@praveen2hearts8 жыл бұрын
Classic video on HashMap... Please keep on posting such classics
@kishorejosyula67948 жыл бұрын
One of the best explanations I have seen!!!!
@chanakakasun94685 жыл бұрын
Recommended video Simply explain how it happens well done