How HashMap works internally || Popular java interview question on collection (HashMap)

preview_player
Показать описание
In this tutorial, we are going to learn how hashmap works internally.This is a very popular java interview question from the collection framework and been asked so many times to check candidates understanding on Map collection.

I am going to cover three things in this series of tutorials which will cover a hashmap internal implementation.

2)Once we will have an overall idea we are going to debug
everything that we learned in this tutorial

In case of a hash collision, then the key with the same hashcode is going to be stored in the same index as each bucket is a node or a linked list.

Inside each bucket, four things are going to be stored as a form of a linked list.They are hashcode, key, value and the next (which hold the address of the next node with the same hashcode).

So lets understand everything diagrammatically because this is one of the very popular hashmap interview questions.So please put this question on your to-do list and better be prepared for it.

“How hashmap works internally in java with example"

subscribe to my channel by clicking on the link below.

Stay tuned and like my Facebook page for more.

Music :
-----------
credits : -
1)
Creative Commons — Attribution 3.0 Unported— CC BY 3.0

(intro)

2)
NCM Epic Music Ender Guney

-----

intro template :
Рекомендации по теме
Комментарии
Автор

If I'm not wrong, it will not create another linked list ..it will just create new node and will make it was next

naturelove
Автор

2 Things I want to add (correct) here

1. When you say a link-list will be added, actually it would be a node added into a particular linkedlist.
2. map.put("null", 4) is not equal to map.put(null, 4). In case of map.put("null", 4) hashcode will be calculated as normal String. What you explained for 0th index is map.put(null, 4).

BuffaloCanCode
Автор

Watched this video yesterday before my Interview and Luckily I was asked to implement my own hashMap. My code worked in the first attempt. Kudos to you explaination.

akshayjeengar
Автор

Hi guys, hope you are doing well !! below is the link to hashmap practical video

Have a nice time !!

SeleniumExpress
Автор

OMG this guy is very nice. he helped to understand any code of java.
thank you!
if you can please give as more please

ajbchannel
Автор

Preparing for interviews and found this very useful thanks a

ashrithareddyrondla
Автор

Nice video. In case of a collision if we add the new <K, V> node to the beginning of the LinkedList in the bucket then we can still achieve O(1) time complexity for put() method instead of O(n). The much elegant solution to improve the hashmap collision performance would be to use self-balancing tree data structure so in the worst case traversal would be O(log n).

prafulsurve
Автор

Thank You so much after so many videos I have understood how it works and Successfully Subscribed❤️❤️❤️

praveenkumarc
Автор

Thank you so much for very good way explained this topic with logic. It’s really helpful for anyone who wants to learn java. Thanks again.

meghatiwari
Автор

Now I really understood how hashmap works internally...u r really amazing brother.great explanation.🙏🙏👍

basavarajnv
Автор

Explained Really well in such a short video. Kudos! Really Prepared before giving Videos on Youtube. I can see good confidence in your presentation. Thanks a ton!

dvoorganisation
Автор

you are explaining very clearly with diagrams.i have not seen like this in any other channels

rameshkvr
Автор

i remember that. when i was young, i make simple like a database, iam using link list, exactly iam using doubly link list .. with 'prev' and 'next' node, good job bro !.

MrSubandrio
Автор

aaa & aab are 2 different keys and hence the hash code will be different. Only the index could be the same and if so the second entry will be added to the linkedlist at that particular index (index 6 in this example). Now assume that I'm trying to put another value with the same key, aaa. Now the hashcode and the index of the current entry and that of the first entry at index 6 are the same. So the value that pass with the key aaa is overwritten. This is what happens when you try to put a value into a hashmap with an already existing key, as we all know the keys are to be unique otherwise the entry will be overwritten. Keep going! Best wishes!

sindhuchary
Автор

Explanation 👌👌👌sir...u look like Telugu movie hero Aadhi. ....s/o Sai Kumar

sumasuripaka
Автор

You have no idea how this video helped me. I have seen a bunch of other videos and the tutorials just make the concept much more complex. Thanks a bunch man! Keep up the good work.

ShadowWalker
Автор

I got a new job because of this tutorial, Thanks much!!!

AnilKumar-nqlp
Автор

By this I got concept internal working hashmao thank you

deepchand
Автор

excellent explaination ...no words needed. please do more videos like this

kumar
Автор

Very Useful content you have provided Thank you so much for making thiss video ...my concepts cleared about hashmap

varshachavan