Тёмный

How HashMap works in Java? With Animation!! whats new in java8 tutorial 

Ranjith ramachandran
Подписаться 40 тыс.
Просмотров 1 млн
50% 1

How does java hashmap work ? HashMap is one of the most popular java.util data structures.
Its one of the associative array implementations, here I have explained its internals in simple terms using an animation. Java8 adds a bit of enhancement to HashMap by using a balanced tree when there is too much has collisions. I have covered that as well.
Please leave your comments if you liked this. Also, subscribe to the channel for updates on similar topics.
#java8 #hashmap #hashcode #java #javaprogramming #javainstitute #javascript #javatutorial #array #beginners #beginner #study #learnjava #learning #fypシ #fypシ゚viral #trending #tutorial

Опубликовано:

 

13 июл 2015

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 1 тыс.   
@RickGladwin
@RickGladwin 4 года назад
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_ss632
@coding_ss632 4 года назад
Thanks Rick
@MuzicalMelody
@MuzicalMelody 4 года назад
How to get the hash value
@yaruiwu7408
@yaruiwu7408 4 года назад
This is just wonderful
@balajikoc1429
@balajikoc1429 4 года назад
Thanks Rick
@adarsh6750
@adarsh6750 4 года назад
Thanks rick
@manishsoni7689
@manishsoni7689 3 года назад
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.
@mohsensm7438
@mohsensm7438 3 года назад
This point is very necessary to complete this good video.
@PavanKumar-yj8fu
@PavanKumar-yj8fu 2 года назад
Very good point, thanks
@ArkAngelHFB
@ArkAngelHFB 2 года назад
Would this mean that without the equals() method call, a HashMap could erroneously overwrite both Key and Value at the same time?
@dmitrikonnov922
@dmitrikonnov922 2 года назад
@@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.
@ArkAngelHFB
@ArkAngelHFB 2 года назад
@@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?
@sent2anil
@sent2anil 8 лет назад
This is the best tutorial I found for "How HashMap works"! Demo using animation is remarkable :)
@madhugali
@madhugali 8 лет назад
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.
@satishpatil115
@satishpatil115 6 лет назад
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 ???
@ayushjindal4981
@ayushjindal4981 6 лет назад
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.
@vishalkumargupta7986
@vishalkumargupta7986 5 лет назад
It does not take double size but size equal to next power of 2.
@v0nnyboy
@v0nnyboy 5 лет назад
You're implicitly stating that it's double ... as a previous power of 2 ( 2^4) is being multiplied by 2 .
@ayushman_sr
@ayushman_sr 5 лет назад
this was important part... yet nit covered
@shyamalmunshi
@shyamalmunshi 8 лет назад
This is probably the best explanation of Hashmap I've come across! Kudos to you!
@areyoucerealtube
@areyoucerealtube 7 лет назад
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!!
@Tanga-ou5im
@Tanga-ou5im 9 часов назад
Best explanation. Perfect
@condor1016
@condor1016 8 лет назад
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.
@saruncse85
@saruncse85 7 лет назад
I was looking for a good explanation for a long time, and I found today. Thanks, Ranjith.
8 лет назад
Excellent job @Ranjith ramachandran! Keep doing it!
@VinodKumar-ng3kc
@VinodKumar-ng3kc 5 лет назад
People who has disliked, what are you guys expecting ? This is just perfect explanation!!
@javatmz
@javatmz 5 лет назад
:) right
@gnanasekaranebinezar7199
@gnanasekaranebinezar7199 5 лет назад
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!!!👏
@RiteshPuj
@RiteshPuj 8 лет назад
I learned a lot about Hashmap from this video. Thanks a lot Ranjith, you have did a great job. :)
@yuyuejiang3278
@yuyuejiang3278 8 лет назад
This is an in-depth very well explained video! Thanks a lot!
@ranjithramachandran5928
@ranjithramachandran5928 8 лет назад
Thanks!
@arvind143100
@arvind143100 4 года назад
@@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. 🙏🙏🙏
@komirellykasanaboina5597
@komirellykasanaboina5597 3 года назад
@@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????
@ronak212
@ronak212 6 лет назад
This got to be the best explanation of Internal working of hasmap that I have ever seen. Thanks..!
@MikeAetherial
@MikeAetherial 8 лет назад
This is the first explanation that has made sense to me! Its like an epiphany! Thank you!
@nabinsaud4656
@nabinsaud4656 3 года назад
Holy shit I was confused about hash tables for so long and this video simplified in such a nice way.
@harshavardhan7
@harshavardhan7 7 лет назад
Dude more videos please :) You are awesome :)
@jackfarah7494
@jackfarah7494 2 года назад
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 RU-vid!
@mirodma
@mirodma 8 лет назад
Amazing approach!! Thanks a lot worked like a charm!!!
@SagarAnkitaUpdates
@SagarAnkitaUpdates 4 года назад
This is the best video that I have seen by now, however its sad that you have stopped posting now
@naveedhassan7399
@naveedhassan7399 3 года назад
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.
@jasper5016
@jasper5016 2 года назад
Good one brother
@vyshnavramesh9305
@vyshnavramesh9305 7 месяцев назад
both hashcode() and equals()
@mandy1339
@mandy1339 5 лет назад
Thank you!! Excellent video
@ArdhenduShekharSingh1508
@ArdhenduShekharSingh1508 8 лет назад
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.
@shadabsheikh51
@shadabsheikh51 8 лет назад
Hey Ranjith Very detailed and nicely animated work..It was easy to understand
@ranjithramachandran5928
@ranjithramachandran5928 9 лет назад
HashMap working animation + enhancements for HashMap in Java8 - check out! If you liked, please leave a comment!
@chilltouchng
@chilltouchng 8 лет назад
+Ranjith ramachandran Really good! This is the best tutorial about "How HashMap works"!
@ChandrakanthReddySoodiReddy
@ChandrakanthReddySoodiReddy 8 лет назад
Very Helpful video on HashMaps. I actually understood how Look up works. Thank you...
@atulkumar-hm6yo
@atulkumar-hm6yo 7 лет назад
Sir,Please share how Hashcode made...!!!!
@satyaprakashnayak1363
@satyaprakashnayak1363 7 лет назад
Very wonderful tutorial....Can you please also explain in animation How ConcurrentHashMap and ConcurrentLinkedQueue works?
@kinjalthehero
@kinjalthehero 7 лет назад
Thank you
@rahulpatil8372
@rahulpatil8372 8 лет назад
Very well explained, now i can easily visualize the Hashmap structure and the way how Key-Value stores. Thanks a lot :)
@arvindaggarwal
@arvindaggarwal 8 лет назад
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......
@daikhostephen7288
@daikhostephen7288 6 лет назад
Correction: Whenever there is collision, the new entry should added as the head of linked list, not tail.
@sameer_sah
@sameer_sah 3 года назад
any references ?
@sergeyvechkitov221
@sergeyvechkitov221 3 года назад
p.next = newNode(hash, key, value, null);
@bsaikumarreddy1413
@bsaikumarreddy1413 2 года назад
Yes. Because the insertion will take O(1) time by inserting at head rather than tail.
@RagPeddabudi
@RagPeddabudi 8 лет назад
this is awesome explanation dude.. The best one for HashMap
@ginny5967
@ginny5967 3 года назад
😭
@ginny5967
@ginny5967 3 года назад
R
@RagPeddabudi
@RagPeddabudi 3 года назад
@@ginny5967 watzup buddy ?
@RagPeddabudi
@RagPeddabudi 3 года назад
@@ginny5967 wat made u cry
@FlexerPivot
@FlexerPivot 5 лет назад
Amazing, thank you for this bro.
@prakashpk6311
@prakashpk6311 5 лет назад
Simply perfect ! Awesome explanation
@vincentkimt
@vincentkimt 8 лет назад
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
@ranjithramachandran5928
@ranjithramachandran5928 8 лет назад
+Vincent Lal Please note the index is calculated as hash & (n-1) which is same as hash % n-1
@raju5081
@raju5081 7 лет назад
it should be n only as the operation always outputs 0 to 15 which are indexes of the table 0 to 15.
@_Vaibs_
@_Vaibs_ 6 лет назад
+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.
@yogeshvbk
@yogeshvbk 8 лет назад
How hash(k) is calculated? Can you please explain..
@ranjithramachandran5928
@ranjithramachandran5928 8 лет назад
+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)
@nsarvesh1012
@nsarvesh1012 8 лет назад
Exceptional presentation of HashMap. Keep up the good work :)
@alenka7891
@alenka7891 6 лет назад
I like when I can see the lecturer on the screen. Good explanation, this is what important in here
@chaitu2037
@chaitu2037 8 лет назад
Good explanation, but can you remove the recording of yourself, frankly it is a little disturbing to watch your head tilt frequently.
@rhimanshu6288
@rhimanshu6288 7 лет назад
true
@nirmitsrivastava
@nirmitsrivastava 7 лет назад
true
@rexroy4037
@rexroy4037 7 лет назад
yes its kind of disturbing ..
@shubhamsrivastava5400
@shubhamsrivastava5400 7 лет назад
lol
@ahmetemreboyaci
@ahmetemreboyaci 6 лет назад
well that's ungrateful
@atulyadav21j
@atulyadav21j 7 лет назад
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.
@etofok
@etofok 7 лет назад
keys are objects, you'll need to run .equals(). integers are much faster to compare via "&"
@skullwise
@skullwise 6 лет назад
I had asked the same question. :-)
@barrettkepler7618
@barrettkepler7618 2 года назад
HashMaps finally demystified. Thank you very much
@taoufik.jabbari
@taoufik.jabbari 7 лет назад
This is the best tutorial i've ever seen for understanding HashMap thanks a lot ! From Morocco
@jonkc3635
@jonkc3635 7 лет назад
Your face is in the way of the slides. lol
@sangitdhanani2137
@sangitdhanani2137 8 лет назад
dude stop coming back and forth in to the screen. Its distracting
@jiezou7297
@jiezou7297 8 лет назад
Thank you very much for the work. Explanation is clear and animation is very good!
@RakeshGajjar
@RakeshGajjar 9 лет назад
Thanks man! I just learnt something from you! Please keep up the good work.
@shikher123yo
@shikher123yo 8 лет назад
perfect video to learn how hashmap works in a very short time.
@jinliu5928
@jinliu5928 8 лет назад
Very good video! Thank you for your explanation.
@rohitmanchanda8412
@rohitmanchanda8412 6 лет назад
Absolutely fantastic use of animation for presentation. understood in one shot. Thanks for taking the pain of wonderful preparation. excellent work!
@clyt9636
@clyt9636 7 лет назад
so well explained!!! implementation details and the class heirarchy in just 15 minutes! You're a great teacher
@Justinryan03
@Justinryan03 4 года назад
We've been doing hashmaps in class a lot and I haven't quite understood it until now. Thank you!
@bikaspatro3329
@bikaspatro3329 8 лет назад
Excellent demonstration of HashMap implementation!!
@huynhmanhhoang5131
@huynhmanhhoang5131 7 лет назад
Great! Today I realize that I misunderstand many things. Thank's.
@anuraag3103
@anuraag3103 6 лет назад
This is the best explanation available in youtube for Hashmap...!!
@bashachand8590
@bashachand8590 5 лет назад
liked, subscribed and i can never forget hashmap implementation for life time now.
@popatkalushe1261
@popatkalushe1261 4 года назад
Thanks a lot, i was really afraid and bit confused about this concept , finally I found this explanation and I'm really so happy.
@gauravsahu90
@gauravsahu90 8 лет назад
Very nicely Explained..Kudos to you (Y)
@srikanthvalluri1956
@srikanthvalluri1956 8 лет назад
very well explained .. Thanks for sharing!
@neetishraj
@neetishraj 6 лет назад
Thank you Ranjith, you strike right into the root concepts that clear all doubts that branch out from that root confusion. Thank you sir
@amolk4339
@amolk4339 8 лет назад
Thank you Ranjith. Appreciate your efforts. This definitely going to make difference to learners... Great job!
@etofok
@etofok 7 лет назад
thanks, amazing presentation
@MBadAtGuitar
@MBadAtGuitar 8 лет назад
Thank you very much for this wonderful piece of work. Now certainly I got an idea of how exactly Hashmap works internally.Gonna check the internal activities of put, get and hash in jdk 8 also. Keep the knowledge flowing. :)
@zcarla3
@zcarla3 5 лет назад
Loved this explanation!! thank you
@KousikPaul
@KousikPaul 8 лет назад
Just Awesome..
@kalyanhr
@kalyanhr 6 лет назад
very well explained. Thanks for the video!!
@TheN0odles
@TheN0odles 8 лет назад
Excellent. Thanks for posting.
@nishikanttayade7446
@nishikanttayade7446 6 лет назад
this is THE BEST EXPLANATION of HashMap...thanks
@timadeshola
@timadeshola 7 лет назад
Nice video, very engaging and loaded. Kuddos
@pritamaries
@pritamaries 8 лет назад
Ranjith, you ROCK man !!!! I think this the most detailed explanation about HashMap.
@raazeev1
@raazeev1 6 лет назад
The animations help remember things.. Kudos...!! Thanks
@maximshen3078
@maximshen3078 8 лет назад
Best HashMap explanation and animation !
@KZwai
@KZwai 5 лет назад
The best! ...and I knew nothing about this complex topic before the video, but now it's my favorite, thank you!
@irynasherepot9882
@irynasherepot9882 4 года назад
Wow, this is the best tutorial about itHashMap on RU-vid!
@jqyang9406
@jqyang9406 7 лет назад
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!!
@sivakrishnat5471
@sivakrishnat5471 2 года назад
hands down this is the best video on how hashmap works internally. Thank you very much.
@mukulanand181
@mukulanand181 8 лет назад
Awesome!! Really enjoyed watching it so much! Thank you!
@chanakakasun9468
@chanakakasun9468 4 года назад
Recommended video Simply explain how it happens well done
@TheFlyguy31
@TheFlyguy31 6 лет назад
Very impressed - thank you!
@priyankabakshi9765
@priyankabakshi9765 8 лет назад
Good Explanation..
@user-vy8sz6mz4s
@user-vy8sz6mz4s 6 лет назад
Отличное объяснение. Огромное спасибо!))))
@ashrafs965
@ashrafs965 4 года назад
It's really sad that you aren't posting videos anymore. you have such great talent in teaching and you were a valuable resource on youtube.
@prasant222
@prasant222 8 лет назад
superb explanation thanxx
@TIGEROFLOVE2527
@TIGEROFLOVE2527 7 лет назад
Thank you. Awesome tutorial!
@DeepakPandey-lz3hy
@DeepakPandey-lz3hy 8 лет назад
Superb explanation Sir, keep it up and keep aspirants enhance their skills.
@cbennett52
@cbennett52 8 лет назад
Thanks for an awesome demonstration and your dedication in making these videos!
@InnerInvocaction
@InnerInvocaction 8 лет назад
I really like visual explanation, Appreciate you and thanks to share
@wtfsamq
@wtfsamq 7 лет назад
Fantastic video, thanks a lot - very clear! It's nice to have the little inserted video of you as well, somehow it helps to improve focus throughout the video
@Jithu0013
@Jithu0013 4 года назад
Best video i have ever found in you tube regarding implementation of hash map .Described it clearly
@sonammittal6723
@sonammittal6723 4 года назад
Best tutorial for understanding HashMap. Thanks a lot !
@TheVitunia
@TheVitunia 7 лет назад
Thank you, sir! Amazing video!
@ryanfrank4299
@ryanfrank4299 8 лет назад
Clear explanation. On a side note its also nice to have a small video of you (the teacher). When I watch videos like this that don't have that I find myself automatically just reading the content on the screen over and over again because your eyes have nowhere else to go. Keep up the good work.
@sandeepsingh-de4fg
@sandeepsingh-de4fg 4 года назад
Great explanation. If anybody want to know how HashMap internally works please watch this video once. Thanks for sharing such amazing video.
@abhinkraj3796
@abhinkraj3796 8 лет назад
This is excellent. Thanks Ranjith. Looking forward to hear more such tutorials from you.
@gagangupta1255
@gagangupta1255 2 года назад
One of the best resource on HashMap. Really stunning !!!
@iMarqs
@iMarqs 9 лет назад
Really helpful, Thank you!
@ravisahu3395
@ravisahu3395 8 лет назад
Great explanation about hashing and collisions...
@thirudoddi8485
@thirudoddi8485 5 лет назад
Nice Presentation of the Map concepts!
@bashachand8590
@bashachand8590 5 лет назад
Thanks a lot sir. I understand and appreciate the effort you have put to explain hashmap implementation in next level by explaining about index calculation from hashcode. which is new to me or most of the people. Usually people talk about hashcode only not index calculation. and comparison of hashcode and then equals and about limits. Lucky i found this video as soon as i faced this question in interview and he was expecting what all you explained about limit and indexing.
@vibhorhadke988
@vibhorhadke988 8 лет назад
Ranjith with the animation it's very easy to understand Internal functionality .Great effort and Thanks
@basavarajpatil8896
@basavarajpatil8896 4 года назад
very well explained. thank you.
@shivanandkohalli9301
@shivanandkohalli9301 7 лет назад
Very clear explanation. Thank you.
@rajesh80
@rajesh80 8 лет назад
Thanks for explaining in such good way.
Далее
JVM ( java virtual machine) architecture - tutorial
29:16
01. Internal Working of HashMap & Java-8 Enhancement
19:11
Equals and hashcode contract
13:50
Просмотров 85 тыс.
Java Memory Model in 10 minutes
10:55
Просмотров 256 тыс.