How HashMap Internally Works in Java With Animation | Popular Java Interview QA | Java Techie

  Рет қаралды 109,458

Java Techie

Java Techie

2 жыл бұрын

This tutorial we will explain you How hash map internally works in java
#javatechie #CoreJava #InterviewQA
GitHub:
github.com/Java-Techie-jt
Blogs:
/ javatechie
Facebook:
/ 919464521471923
guys if you like this video please do subscribe now and press the bell icon to not miss any update from Java Techie
Disclaimer/Policy:
--------------------------------
Note : All uploaded content in this channel is mine and its not copied from any community ,
you are free to use source code from above mentioned GitHub account

Пікірлер: 159
@GamesOfGalaxies
@GamesOfGalaxies 6 ай бұрын
I have seen many videos on this topic but no one explained this topic as simpler and easy as you explained...thank you so much bhagwaan apki har muraad puri kare
@poojababar8746
@poojababar8746 5 күн бұрын
Sidhi bat no bakwas vala explanation, straight, simple , good work sir
@rohitkhandelwal319
@rohitkhandelwal319 Жыл бұрын
I saw more than 50 videos on hashing , but this was the one which made me actually understand, thankyou sir.
@Javatechie
@Javatechie Жыл бұрын
Thanks Rohit. Keep learning 😃
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
bro , if there kar 2 null key then second value will be placed in ??
@rohitkhandelwal319
@rohitkhandelwal319 Жыл бұрын
@@PIYUSH-lz1zq I think 0th bucket
@rohitkhandelwal319
@rohitkhandelwal319 Жыл бұрын
@@Javatechie am I right?
@Javatechie
@Javatechie Жыл бұрын
Yes correct
@subhamsharma8268
@subhamsharma8268 Жыл бұрын
That is a very simplified and a splendid explaination of hashmap. Thank you so much sir.❤
@prajwalbandekar3557
@prajwalbandekar3557 7 ай бұрын
The BEST easy explanation out there, Thank you Sir 🤝
@PraveenKumarpksksit
@PraveenKumarpksksit 4 ай бұрын
Thankyou for so much detailed and simplified way of teaching HashMap. It is really helpful for anyone who wants to either learn fresh or just wants to revise again. Really Appreciate !!
@user-fl2yu2yj5e
@user-fl2yu2yj5e 7 ай бұрын
Thank you so much for this explanation! It's really clear with the examples you did :D
@ranjithkumarravichandiran8983
@ranjithkumarravichandiran8983 Жыл бұрын
Thank you so much for clear explanation.👏👏
@chetanbhandari3033
@chetanbhandari3033 2 жыл бұрын
Awesome explanation waiting more interviews questions videos
@maankhurana5814
@maankhurana5814 5 ай бұрын
Awesome watched 10 more videos on youtube before this .... not able tp understand concept... but u made it very simple ... Thanks alot
@pateldharmesh1361
@pateldharmesh1361 6 ай бұрын
Bhai your tutorial clears all doubts most of the time
@muralitreddy
@muralitreddy 2 жыл бұрын
Simple and neat explain
@sameerkadgaye2048
@sameerkadgaye2048 2 жыл бұрын
Very clear explanation thank you sir
@raghugupta8959
@raghugupta8959 Жыл бұрын
i understand very clear,thanks for explaining neatly🙂🙂
@raghavagarwal6545
@raghavagarwal6545 9 ай бұрын
Simple awesome explanation👍
@charangowda384
@charangowda384 Жыл бұрын
Bro I have seen a lot of videos , but this is by far the best explanation video i have seen on youtube clean, simple and clear.
@Javatechie
@Javatechie Жыл бұрын
Thanks buddy 😊. Glad to hear this ☺️
@sergiogb
@sergiogb 2 жыл бұрын
Thanks, good an easy to understand
@priyay
@priyay Жыл бұрын
Simple and clear thankyou
@nagireddy1507
@nagireddy1507 2 жыл бұрын
very clear explanation... Thank you
@manamohansamal1040
@manamohansamal1040 2 жыл бұрын
Brother your explanation helps to easily understand the topic. ❤️❤️ One request if you can make a video one interview questions with different types of url mapping to the dispatcher servlet like /,/*,/** etc . It will be very helpful 🙏🙏
@Javatechie
@Javatechie 2 жыл бұрын
Okay I will do that. This is kind of URL patterns
@raajaakowsalya2711
@raajaakowsalya2711 Жыл бұрын
Hey!!! Seriously well explained 😀❤️✨✨
@priyankashaw1238
@priyankashaw1238 Жыл бұрын
Your explanation is to the point and very clear. Request you to also add how hashmap retrieval works when there is more than 1 key in the same bucket.
@Javatechie
@Javatechie Жыл бұрын
Okay i will buddy
@ramyasruthi5372
@ramyasruthi5372 2 ай бұрын
Thank you!!! Very detailed
@mintybreez
@mintybreez 2 жыл бұрын
Very well explained 👏
@pirate1239
@pirate1239 Жыл бұрын
best explanation. easy one
@vinaypandey4752
@vinaypandey4752 Жыл бұрын
Awesome explination
@rajraj8065
@rajraj8065 2 жыл бұрын
Awesome explained, keep making such a good vedio .
@murugeshk14
@murugeshk14 Жыл бұрын
Thank u it's was short and simple 🙌
@supun_sandaruwan
@supun_sandaruwan 5 ай бұрын
All In one video Thank you sir 💖
@zuggrr
@zuggrr Жыл бұрын
thank you soooo muchh ! you are the best
@TanishKumar-uz4wk
@TanishKumar-uz4wk Жыл бұрын
Great !!!
@selvapandymoorthy4173
@selvapandymoorthy4173 2 жыл бұрын
Great explanation
@vivekkumar-iy7zk
@vivekkumar-iy7zk 4 ай бұрын
Thanks you explained so well
@forouzannaderi-vw3sp
@forouzannaderi-vw3sp 22 күн бұрын
great explanation thank you so much 😍👏
@girishrp9339
@girishrp9339 2 жыл бұрын
In youtube have more than 1000+ videos same question but your video is very easy to understand.
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy 😊
@user-fn3ko9zw7z
@user-fn3ko9zw7z 10 ай бұрын
this is simplified. thank ..
@AbhijitDixit-ki1oo
@AbhijitDixit-ki1oo 4 ай бұрын
Thank you so much sir 🙏
@kirane5911
@kirane5911 Жыл бұрын
Very good explanation
@acchutdevkule7841
@acchutdevkule7841 2 жыл бұрын
You are one of the underrated tech youtuber ...
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy 🙂 for your word . Will hope to grow soon .
@sudheergundubogula
@sudheergundubogula 2 жыл бұрын
Thank you so much ❤️
@VishalSharma-rn7mt
@VishalSharma-rn7mt 7 ай бұрын
Awesome
@scoobydooby4672
@scoobydooby4672 Жыл бұрын
Nice thanks
@vipintekade6400
@vipintekade6400 Жыл бұрын
Lovely .
@mohammedajazquadri7869
@mohammedajazquadri7869 Жыл бұрын
brilliant explanation
@RaviShankar-xy6zh
@RaviShankar-xy6zh 2 жыл бұрын
Bro you always bring great and interesting videos in eloquent way.
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy 😊
@subramanianchenniappan4059
@subramanianchenniappan4059 Жыл бұрын
thanks bro. useful for interviews. i am a java backend restful API project tech lead. will apply for job
@simplyarranged
@simplyarranged Жыл бұрын
Thanks sir🎉
@learnprogramming6930
@learnprogramming6930 Жыл бұрын
Thank you
@devopsshiv3842
@devopsshiv3842 Жыл бұрын
Yes, i got the internal hashing collision part
@sivarama8116
@sivarama8116 Жыл бұрын
Tx sir
@naveenkumardasari
@naveenkumardasari 4 ай бұрын
It would be more helpful, if you explained about retrieving elements from hashmap.
@Javatechie
@Javatechie 3 ай бұрын
Will do another video
@snehakarosiya2618
@snehakarosiya2618 2 ай бұрын
thank you so muchh !!
@amscoder5262
@amscoder5262 2 жыл бұрын
Simply awesome explanation brother 👌👌👌
@Javatechie
@Javatechie 2 жыл бұрын
Thanks brother 🤗
@Nikhil-jf7lv
@Nikhil-jf7lv 3 ай бұрын
Welcome to java tikki ❤
@natureParadise777
@natureParadise777 2 жыл бұрын
Like your videos, you explain the topic in very beautiful way, please make more videos on the interview questions...
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy 😊
@ankush_in_sync5998
@ankush_in_sync5998 Жыл бұрын
Thanks
@pranavjog172
@pranavjog172 6 ай бұрын
Hi, Could you please make a video on HashMap internal working in Java 8 or new addition in Java8 for HashMap?
@basitali9651
@basitali9651 2 жыл бұрын
Thanks for this info..God job sir
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy
@pradeepnayak1988
@pradeepnayak1988 2 жыл бұрын
Great Work Basant. Keep Growing.
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy
@pratishrutipanda6461
@pratishrutipanda6461 2 жыл бұрын
You nailed it 🔥🔥🔥
@Javatechie
@Javatechie 2 жыл бұрын
Thanks Pratishruti 🙂
@praveens2272
@praveens2272 2 жыл бұрын
Nice explanation
@Javatechie
@Javatechie 2 жыл бұрын
Thanks 😊
@priyanaik4099
@priyanaik4099 Жыл бұрын
Awesome explanation. Thank you. Can you make video for springboot?
@tolgacelikart
@tolgacelikart 18 күн бұрын
great explanation , and thanks for sharıng. Just little feedback maybe :) same pronunciation was distracting me time to time on focusing, such as zero (sounds g..), hash (has), etc. also some of saying 'ok , fine, right, after explaning something etc ' .
@GamesOfGalaxies
@GamesOfGalaxies 6 ай бұрын
I am subscribing your channel just because of this video
@Javatechie
@Javatechie 6 ай бұрын
Keep learning 👍 I believe you like other videos as well
@soumyaranjan6196
@soumyaranjan6196 2 жыл бұрын
Awesome explanation bro 😊
@Javatechie
@Javatechie 2 жыл бұрын
Thanks Soumya 😊
@Akhilesh_Reddy
@Akhilesh_Reddy 2 жыл бұрын
Good one Basant.
@Javatechie
@Javatechie 2 жыл бұрын
Thanks buddy 😊
@maheshrevaskar7658
@maheshrevaskar7658 Жыл бұрын
Thanks Basant! Video on working on ConcurrentHashMap will be helpful. Saw many videos, but still its not clear.
@Javatechie
@Javatechie Жыл бұрын
Sure i will do that
@MaheshAnand1995
@MaheshAnand1995 Жыл бұрын
Should have been more helpful if you explained the get process as well. Thank you
@Satenc0
@Satenc0 2 жыл бұрын
Very good explanation sir overall, but I have one little question about the hash collision, at min 5:38 you say that it first uses double equals (==) to check if they have the same hashcode, which means to check if they have the same reference right, if they result to have the same hashcode then it will just replace, but if they dont, then it will check if they have the same value (content) with .equals() method (key1.equals(key2)) right, if it is true then replace, if not then add the next node, is this well understood? please correct me if not
@Javatechie
@Javatechie 2 жыл бұрын
Yes your understanding is correct
@ranachan5555
@ranachan5555 Ай бұрын
I am not finding you concurrent Hashmap in your list, Please send the link
@adityavyas6603
@adityavyas6603 2 жыл бұрын
Very nice explanation Basant... One question if we change the content of employee object after adding as key in map then what happened.. And in case of immutable employee class what is the behavior of map. Thanks in advance..
@Javatechie
@Javatechie 2 жыл бұрын
If you will do get (key) you will get NPE
@user-eg6yo3uh4b
@user-eg6yo3uh4b 5 ай бұрын
5:03 Correct me if I am wrong but if (e1,"Dev") & (e3,"UI") both coincidentally have the same hash value, then wouldn't the hash value for second linked list at 6 be 1011, just like the linked list above it?
@pravin.a.mahajan
@pravin.a.mahajan 23 күн бұрын
Hi Basant, Recently I got one question from interview that, will it create bucket of 16 when you create map instance? I did debug the code and found that it creates bucket when you first element into map. your explaination at 1:00
@Javatechie
@Javatechie 22 күн бұрын
That's correct but will cross validate and update you
@vinaypandey4752
@vinaypandey4752 Жыл бұрын
Sir, what will happen, if a duplicate value is given to add, will it will check for duplicate value? Suppose if we have same value in index 1 and same value is send again to add on index 3, it will add or it will not add it?
@mohammedajazquadri7869
@mohammedajazquadri7869 Жыл бұрын
Sir please make videos on design patterns it is mostly Asking now a days in interview
@Javatechie
@Javatechie Жыл бұрын
Okay buddy I will
@mlevidigeri
@mlevidigeri 2 жыл бұрын
You’re videos very helpful. Can you please do a video on java events
@Javatechie
@Javatechie 2 жыл бұрын
Java or spring events ?
@mlevidigeri
@mlevidigeri 2 жыл бұрын
@@Javatechie spring events
@Javatechie
@Javatechie 2 жыл бұрын
Okay I will do that
@vasuimandi5535
@vasuimandi5535 2 жыл бұрын
Bro, can you make a video on mock interviews or can you make video on all common interview questions in Java, So that will be helpful to those who wants to change company....
@Javatechie
@Javatechie 2 жыл бұрын
Hi vasu , please check below link it's already there for core java kzbin.info/www/bejne/nHfRppioaKZ3brM
@Javatechie
@Javatechie 2 жыл бұрын
Part 2 : kzbin.info/www/bejne/fYCZaHZti5J8mLM
@gavadesandip81
@gavadesandip81 2 жыл бұрын
@@Javatechie Thanks
@jagadeeshbelagallu5243
@jagadeeshbelagallu5243 2 жыл бұрын
If put Method find same content what will happen? is it throw error or ignoring to store the content into that object? If e1.equals(e3 is it override e3 content?
@aloktiwari4188
@aloktiwari4188 2 жыл бұрын
Hi sir please make video with Java 17 example
@sivakrishna2544
@sivakrishna2544 4 ай бұрын
Hi bro can you make one vidow difference between 1.7 and 1.8 difference in HashMap internal architecture
@Javatechie
@Javatechie 4 ай бұрын
Sure will do that
@sivakrishna2544
@sivakrishna2544 4 ай бұрын
Thanks a lot bro❤
@shubhammahindru3563
@shubhammahindru3563 2 жыл бұрын
Hi, why is the size is still one ? Car car = new Car("Seletos",2020); Map carMap = new HashMap(); carMap.put(car,"1"); carMap.put(car,"2"); System.out.println(carMap.size()); In car class, I have the following implementation of the equals and hashcode ? @Override public boolean equals(Object o) { return false; } @Override public int hashCode() { return 1; } car.equals(car) will give it false and it should have added it as the next node but its giving the size as 1 and only node its adding ? I am confused in this please help, if u got some time. is it ? if the keys are same then it first checks == if not then only it goes for equals comparison ?
@Javatechie
@Javatechie 2 жыл бұрын
In both the case hashcode will be 1 only right which is again duplicate
@shubhammahindru3563
@shubhammahindru3563 2 жыл бұрын
@@Javatechie Yes 1 but it should go and check for equals method which would return false(because of overridden method) and would add the value as next node ? So it means for duplicate keys equals method is also not checked it simply replaces the value ?
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
bro , if there kar 2 null key then second value will be placed in ??
@Javatechie
@Javatechie Жыл бұрын
Yes
@murugeshk14
@murugeshk14 Жыл бұрын
If u first put(null, 8); its stored in the 0 th index and if again u try to put(null, 9); Then that first entry get replaced by this new entry in the same 0th index as in hashmap duplicate keys are not allowed, if u try to add entry with same key it's gets override
@Hamza-Shreef
@Hamza-Shreef Жыл бұрын
5:47 I think if it finds the same reference or the same value it will throw an exception right ? and there is no replacement happening there.
@Javatechie
@Javatechie Жыл бұрын
No it won't throw any exception just debug and see
@Hamza-Shreef
@Hamza-Shreef Жыл бұрын
@@Javatechie Yes i mean i'm sorry i'm a c# developer and we have a dictionary instead of hash map but i thought they were the same . thank you for pointing that out to me ❤❤
@PIYUSH-lz1zq
@PIYUSH-lz1zq Жыл бұрын
bro , if there kar 2 null key then second value will be placed in ??
@1stnamelastname24
@1stnamelastname24 10 ай бұрын
If "key" is null then it will placed at 0th bucket then what if "Value" is also null ?
@saudsiddiqui5698
@saudsiddiqui5698 2 жыл бұрын
How to access the entry having null key? like map.get("?");
@kishorep5572
@kishorep5572 2 жыл бұрын
Guys, what is the out of it? Map map = new HashMap(); map.put("a", "B"); map.put("a", "C"); map.put(null, "C"); map.put(null, "C"); map.put(null, "A"); System.out.println(map);
@Javatechie
@Javatechie 2 жыл бұрын
Output will be a, C and null , A
@codecompany7114
@codecompany7114 2 жыл бұрын
ok good, but what is the importance of Next then?
@NSINGHK
@NSINGHK 8 ай бұрын
It doesn't have linkedlist, it uses resizable array thsts why it fetch in O(1) time, if its linkedList it will fetch map.get(key) in O(n) which is wrong
@Javatechie
@Javatechie 8 ай бұрын
Hello buddy, It depends on many things. It's usually O(1), with a decent hash which itself is constant time... but you could have a hash which takes a long time to compute, and if there are multiple items in the hash map which return the same hash code, get will have to iterate over them calling equals on each of them to find a match. In the worst case, a HashMap has an O(n) lookup due to walking through all entries in the same hash bucket (e.g. if they all have the same hash code). Fortunately, that worst case scenario doesn't come up very often in real life, in my experience. So no, O(1) certainly isn't guaranteed - but it's usually what you should assume when considering which algorithms and data structures to use. In JDK 8, HashMap has been tweaked so that if keys can be compared for ordering, then any densely-populated bucket is implemented as a tree, so that even if there are lots of entries with the same hash code, the complexity is O(log n). That can cause issues if you have a key type where equality and ordering are different, of course. And yes, if you don't have enough memory for the hash map, you'll be in trouble... but that's going to be true whatever data structure you use.
@MadhusudhanNalla
@MadhusudhanNalla 4 ай бұрын
what if, the equals method returns true? time:4:45
@Regnarr39
@Regnarr39 5 ай бұрын
Ok? Ok
@leandromarcelo2340
@leandromarcelo2340 11 ай бұрын
could you activate the subtitles? pls
@Javatechie
@Javatechie 11 ай бұрын
Please click on CC while watching video. I already enabled it buddy 😊
@zsoltgeza
@zsoltgeza Жыл бұрын
You should create captions, because they cannot be created automatically under Your video
@Javatechie
@Javatechie Жыл бұрын
Didn't get you buddy
@sivabalarasup7556
@sivabalarasup7556 Жыл бұрын
I think, he is referring to Subtitles. You could add subtitles.
@zsoltgeza
@zsoltgeza Жыл бұрын
@@sivabalarasup7556 thats right
@itsnarahari
@itsnarahari 2 жыл бұрын
Bro in which company ur working on ?
@Javatechie
@Javatechie 2 жыл бұрын
Walmart buddy
@RN-jo8zt
@RN-jo8zt 2 жыл бұрын
what if two duplicatre was there in put() .you missed this VVVV.important concept
@vandanac2244
@vandanac2244 10 ай бұрын
If key is duplicate it will be overriden
@Javatechie
@Javatechie 10 ай бұрын
Yes
@10000Deepak
@10000Deepak 2 ай бұрын
it does not matches the content itself, unless you have overriden equals method, you are mistaken here
@adornwithasha2742
@adornwithasha2742 2 жыл бұрын
java techie, info is incomplete.
@Javatechie
@Javatechie 2 жыл бұрын
What is missed here ?
@praveenreddy9454
@praveenreddy9454 Жыл бұрын
@@Javatechie nice explanation but you did not explain about retrieving the keys from hashMap ,main how do you handle if one bucket having multiple nodes ?
@Javatechie
@Javatechie Жыл бұрын
This is put scenarios not get and for get() scenarios there is no complexity . Even though in a single bucket there are multiple nodes , Hashmap internally use hash value so there is no conflict simply it will call map.get(obj) then based on object it will check corresponding hash value and return the object
@roopkishore785
@roopkishore785 Жыл бұрын
At 5:02 of time, [e1 | Dev | 1011 | null] and [e3 | UI | 7976 | null].... My question is why e1 and e3 have different hash values? shouldn't it be same for both?
@Javatechie
@Javatechie Жыл бұрын
Why you are expecting same hash value for 2 different object
@roopkishore785
@roopkishore785 Жыл бұрын
@@Javatechie Because You said in the video, at 4:35 of time, both have same hash.
@Javatechie
@Javatechie Жыл бұрын
I said let's assume both are getting the same hash value what map internally evaluated
@roopkishore785
@roopkishore785 Жыл бұрын
@@Javatechie But collision occurs when we have same hash? and same hash value will give us same index in the bucket??
@roopkishore785
@roopkishore785 Жыл бұрын
@@murugeshk14 No, sir, you're wrong here, Index value is calculated as : [index = hash & (n - 1)] , two objects giving same index means, they have same hash value. Same hash value means they'll fall into same bucket. The concept is "Two different objects can have same hash values".
@shiva5600
@shiva5600 2 жыл бұрын
Thanks
@Javatechie
@Javatechie 2 жыл бұрын
Thanks Shiva 😊
01. Internal Working of HashMap & Java-8 Enhancement
19:11
WebEncyclop Tutorials
Рет қаралды 104 М.
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 24 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 1,7 МЛН
Java 8 Streams | map () & flatMap() Example | JavaTechie
15:37
Java Techie
Рет қаралды 208 М.
SOLID Design Principles in java with Example | JavaTechie
34:44
Java Techie
Рет қаралды 178 М.
How HashMap works in Java? With Animation!! whats new in java8 tutorial
15:29
Ranjith ramachandran
Рет қаралды 1 МЛН
Samsung Galaxy Unpacked July 2024: Official Livestream
4:6:01
Samsung
Рет қаралды 1,4 МЛН
НЕ ПОКУПАЙ СМАРТФОН, ПОКА НЕ УЗНАЕШЬ ЭТО! Не ошибись с выбором…
15:23
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 2,9 МЛН
ИГРОВОВЫЙ НОУТ ASUS ЗА 57 тысяч
25:33
Ремонтяш
Рет қаралды 346 М.