Це відео не доступне.
Перепрошуємо.
How HashMap Internally Works in Java With Animation | Popular Java Interview QA | Java Techie
Вставка
- Опубліковано 25 гру 2021
- This tutorial we will explain you How hash map internally works in java
#javatechie #CoreJava #InterviewQA
GitHub:
github.com/Jav...
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
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
I saw more than 50 videos on hashing , but this was the one which made me actually understand, thankyou sir.
Thanks Rohit. Keep learning 😃
bro , if there kar 2 null key then second value will be placed in ??
@@PIYUSH-lz1zq I think 0th bucket
@@Javatechie am I right?
Yes correct
Sidhi bat no bakwas vala explanation, straight, simple , good work sir
That is a very simplified and a splendid explaination of hashmap. Thank you so much sir.❤
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.
Okay i will buddy
You are one of the underrated tech youtuber ...
Thanks buddy 🙂 for your word . Will hope to grow soon .
In youtube have more than 1000+ videos same question but your video is very easy to understand.
Thanks buddy 😊
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 🙏🙏
Okay I will do that. This is kind of URL patterns
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.
Thanks buddy 😊. Glad to hear this ☺️
Awesome watched 10 more videos on youtube before this .... not able tp understand concept... but u made it very simple ... Thanks alot
Bhai your tutorial clears all doubts most of the time
The BEST easy explanation out there, Thank you Sir 🤝
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 !!
Simple and neat explain
Awesome explanation waiting more interviews questions videos
Very clear explanation thank you sir
I am subscribing your channel just because of this video
Keep learning 👍 I believe you like other videos as well
Thank you so much for this explanation! It's really clear with the examples you did :D
Thanks, good an easy to understand
Thank you so much for clear explanation.👏👏
It would be more helpful, if you explained about retrieving elements from hashmap.
Will do another video
Awesome explained, keep making such a good vedio .
great explanation thank you so much 😍👏
Simple and clear thankyou
Hi, Could you please make a video on HashMap internal working in Java 8 or new addition in Java8 for HashMap?
i understand very clear,thanks for explaining neatly🙂🙂
Hey!!! Seriously well explained 😀❤️✨✨
I love this channel's content
Thanks buddy but BTW what is
@@Javatechie haha, no, it’s ❤️ thanks for the content!
Simply awesome explanation brother 👌👌👌
Thanks brother 🤗
thanks bro. useful for interviews. i am a java backend restful API project tech lead. will apply for job
thank you soooo muchh ! you are the best
best explanation. easy one
Yes, i got the internal hashing collision part
Very good explanation
Simple awesome explanation👍
Awesome explination
Thanks you explained so well
very clear explanation... Thank you
Thank you!!! Very detailed
Welcome to java tikki ❤
Nice explanation
Thanks 😊
Great !!!
Bro you always bring great and interesting videos in eloquent way.
Thanks buddy 😊
Thank you so much sir 🙏
this is simplified. thank ..
All In one video Thank you sir 💖
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
Yes your understanding is correct
Great explanation
Great Work Basant. Keep Growing.
Thanks buddy
Awesome
Like your videos, you explain the topic in very beautiful way, please make more videos on the interview questions...
Thanks buddy 😊
brilliant explanation
Thank u it's was short and simple 🙌
Thank you
Thanks for this info..God job sir
Thanks buddy
Lovely .
Thanks
Very well explained 👏
I am not finding you concurrent Hashmap in your list, Please send the link
You nailed it 🔥🔥🔥
Thanks Pratishruti 🙂
Thanks Basant! Video on working on ConcurrentHashMap will be helpful. Saw many videos, but still its not clear.
Sure i will do that
Nice thanks
Thank you so much ❤️
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
That's correct but will cross validate and update you
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 ' .
Thanks sir🎉
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..
If you will do get (key) you will get NPE
Should have been more helpful if you explained the get process as well. Thank you
thank you so muchh !!
Good one Basant.
Thanks buddy 😊
Awesome explanation bro 😊
Thanks Soumya 😊
Tx sir
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?
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);
Output will be a, C and null , A
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?
5:38 here you said Map first internally used == operator to check the reference and if it is different then it will use equals method. But in the last diagram you haven't showed this ?
Sir please make videos on design patterns it is mostly Asking now a days in interview
Okay buddy I will
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 ?
In both the case hashcode will be 1 only right which is again duplicate
@@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 ?
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?
Awesome explanation. Thank you. Can you make video for springboot?
You’re videos very helpful. Can you please do a video on java events
Java or spring events ?
@@Javatechie spring events
Okay I will do that
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.
No it won't throw any exception just debug and see
@@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 ❤❤
bro , if there kar 2 null key then second value will be placed in ??
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....
Hi vasu , please check below link it's already there for core java
ua-cam.com/video/fFnuer3AD8Q/v-deo.html
Part 2 : ua-cam.com/video/GO67C7V-IbQ/v-deo.html
@@Javatechie Thanks
bro , if there kar 2 null key then second value will be placed in ??
Yes
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
Hi bro can you make one vidow difference between 1.7 and 1.8 difference in HashMap internal architecture
Sure will do that
Thanks a lot bro❤
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
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.
If "key" is null then it will placed at 0th bucket then what if "Value" is also null ?
Hi sir please make video with Java 17 example
How to access the entry having null key? like map.get("?");
Bro in which company ur working on ?
Walmart buddy
ok good,
but what is the importance of Next then?
You should create captions, because they cannot be created automatically under Your video
Didn't get you buddy
I think, he is referring to Subtitles. You could add subtitles.
@@sivabalarasup7556 thats right
could you activate the subtitles? pls
Please click on CC while watching video. I already enabled it buddy 😊
what if, the equals method returns true? time:4:45
it does not matches the content itself, unless you have overriden equals method, you are mistaken here
what if two duplicatre was there in put() .you missed this VVVV.important concept
If key is duplicate it will be overriden
Yes
Ok? Ok
java techie, info is incomplete.
What is missed here ?
@@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 ?
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
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?
Why you are expecting same hash value for 2 different object
@@Javatechie Because You said in the video, at 4:35 of time, both have same hash.
I said let's assume both are getting the same hash value what map internally evaluated
@@Javatechie But collision occurs when we have same hash? and same hash value will give us same index in the bucket??
@@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".
Thanks
Thanks Shiva 😊