Well this is the one which was very much needed.before it started i had handful of questions,but believe me it miraculously clarified all of my doubts. Thanks a lot Naveen🙏 you deserve respect...❤️
I am following Naveen from 10k subscribers and he helped me a lot in my automation career...now the count is growing hope it will reach to an infinite loop...
Your teaching is very very nice...realy from my heart ..thank you ,thank you, thank you...I found your channel firstly at javaMCAP course there are your vedios for collection framework... Great teaching🙏🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻💞💞💞
Hi Naveen , every concept is very well explained. Can you please include this question as well and explain :->what if we don't override the hashcode() /equals() method in our custom classes. thx
if we will not override hashCode() method in in our custom class then default implementation of hashCode() will be called which is present in Object class, we will get a unique number for every object of custom class whether two objects contain same info like id and name are same e.g Employee emp1=new Employee(101, "Naveen"); Employee emp2(101,"Naveen"); there are two object emp1 and emp2 having same id and name, still we will get different hashCode() for every object, by using int hashCode Value1=emp1.hashCode(); System.out.println(hashCodeValue1) and using int hashCodeValue2=emp1.hashCode(); System.out.println(hashCodeValue2); we will get different hashcode value for both objects if you we will not override hashCode() method but if we will override hashCode() method based upon these two attribute id and name, we will get same hashcode value for two objects having same info (means we are putting same employee info two times) like above where id and name is same.
Hi Naveen Thanks for the amazing video. In question 10 I have a doubt: We can store duplicate value in Java HashMap: Corresponding to different keys we can have the same values. for e.g hm.put("Archit",1) hm.put("Naveen",1)
Also in Question 21 When two keys are having the same hascode? Yes, obviously the Collison will happen. But after it will check using equals() method whether the two keys are same or not. if not same then it will create a node in the particular index of the bucket else it will override the value. @Naveen please correct me if am wrong.
When we trying to add duplicate key with same value or new value , it will override with new value. Here my question is what happens to that old value , is it stored in somewhere or is it garbage collected ? i was faced this question in an interview.
Thank you Naveen for making such informative videos. I have a confusion regarding keys returning same hashcode, if it happens how will get method return right value for corresponding key as hashcode is stored in node values to perform equals method, I think its index value which is returned same.Correct me if I am wrong.
hashcode = get(key) - internally the hashcode of this key is calculated then this hashcode is passed as an argument to hash function and then this hash value is passed to indexFor method which calculates the index/bucket/node. Then the equals method is invoked which checks whether the key passed matches with the key present at that particular node if the key matches then the value corresponding to the key is returned but if the key does not match which could be the case when multiple keys have the same hashcode i.e. collision case in this case at the same index we have multiple nodes in which object is stored as a linked list. So if the key does not match with the 1st key present at that node then the same operation is repeated until the key matches.
Is threshold value 8 to convert from linkedlist to balanced tree? I see at 8 it will reorganize by increasing the size of hashmap, at 64 it will convert to tree. I see value Min_treeify = 64. Also can you explain at what threshold it will convert back to linkedlist from tree.
If HashMap internally uses Hashtable, then how come it is accepting null key? because hashtable do not allow nulll values. My doubt is while inserting values inside hashmap, where they will get inserted? in hashtable or at that index of hashtable new linked is created?and first element is added in that list?
Can you sort HashMap in java? I feel answer is yes. As we can sort it according to keys or values also. Like below for sort it accordingly to keys. public class SortedHashMap { public static void main(String[] args) {
Well this is the one which was very much needed.before it started i had handful of questions,but believe me it miraculously clarified all of my doubts. Thanks a lot Naveen🙏 you deserve respect...❤️
Yes Naveen had earned the respect by giving very good content & with correct direction to the community, he is best always 😊👍
I am following Naveen from 10k subscribers and he helped me a lot in my automation career...now the count is growing hope it will reach to an infinite loop...
Naveen - Q no : 10 - It can store multiple duplicate values as long as keys are different..
Your teaching is very very nice...realy from my heart ..thank you ,thank you, thank you...I found your channel firstly at javaMCAP course there are your vedios for collection framework... Great teaching🙏🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻👍🏻💞💞💞
Naveen -you are simply superb, in one word all I can say is you have solved the pain of million automation associates .
Perfectly summarized. Appreciate your time and efforts !
This is really useful and much needed. Thanks for your service to the community.
Excellent explanation as always. Thanks for creating this video. This is very much needed!
Thank you so much for all Hashmap videos sir and happy kannada rajyotsava..
Same to you :)
@@naveenautomationlabs thanks sir
Thanks sir for making such greatly needed topic wise videos
Awesome i was waiting for this
Thank you very much for your help
Very Informative
Thanks for sharing 👍
Really appreciate your efforts
thanks a lot
Appreciated Thanks for creating this video
Simply amazing 👌
Wonderful video ☺️
Hi Naveen , every concept is very well explained. Can you please include this question as well and explain :->what if we don't override the hashcode() /equals() method in our custom classes. thx
if we will not override hashCode() method in in our custom class then default implementation of hashCode() will be called which is present in Object class, we will get a unique number for every object of custom class whether two objects contain same info like id and name are same e.g Employee emp1=new Employee(101, "Naveen"); Employee emp2(101,"Naveen"); there are two object emp1 and emp2 having same id and name, still we will get different hashCode() for every object, by using int hashCode Value1=emp1.hashCode(); System.out.println(hashCodeValue1) and using int hashCodeValue2=emp1.hashCode(); System.out.println(hashCodeValue2); we will get different hashcode value for both objects if you we will not override hashCode() method but if we will override hashCode() method based upon these two attribute id and name, we will get same hashcode value for two objects having same info (means we are putting same employee info two times) like above where id and name is same.
Hi Naveen
Thanks for the amazing video.
In question 10 I have a doubt: We can store duplicate value in Java HashMap:
Corresponding to different keys we can have the same values.
for e.g
hm.put("Archit",1)
hm.put("Naveen",1)
Also in Question 21
When two keys are having the same hascode?
Yes, obviously the Collison will happen.
But after it will check using equals() method whether the two keys are same or not. if not same then it will create a node in the particular index of the bucket else it will override the value.
@Naveen please correct me if am wrong.
@@ARCHIT980 you are right.
Great Questions Sir. Hats off.
Amazing video. Thank you Naveen
Awsome video. One query Navin bhai what is multi threading how its performing in java and impact on hashmap value?
Superb
Very helpful your tutorials, Thank you sir!!!
Thank you so much for the collections
Why dont you try multithreading and spring boot?
Thanks Naveen for such a good content
Thanks for watching
🙏🙏🙏🙏 great effort in creating this ...👍👍👍👍👍👍👍👍 thanks Naveen
My pleasure 😊
Great explanation 👍
Great job......
Nice Naveen.. 🙏
Congrats for 132 K Subscribers in your channel .
Thank you vinod
On what basis binary tree decide what to store left and what to store on right ? Is it by hashcode value ?
When we trying to add duplicate key with same value or new value , it will override with new value. Here my question is what happens to that old value , is it stored in somewhere or is it garbage collected ?
i was faced this question in an interview.
💛
Thank you Naveen for making such informative videos. I have a confusion regarding keys returning same hashcode, if it happens how will get method return right value for corresponding key as hashcode is stored in node values to perform equals method, I think its index value which is returned same.Correct me if I am wrong.
hashcode = get(key) - internally the hashcode of this key is calculated then this hashcode is passed as an argument to hash function
and then this hash value is passed to indexFor method which calculates the index/bucket/node.
Then the equals method is invoked which checks whether the key passed matches with the key present at that particular node if the key matches then the value corresponding to the key is returned but if the key does not match which could be the case when multiple keys have the same hashcode i.e. collision case in this case at the same index we have multiple nodes in which object is stored as a linked list. So if the key does not match with the 1st key present at that node then the same operation is repeated until the key matches.
Thank you so much 👍
You are welcome
Is threshold value 8 to convert from linkedlist to balanced tree? I see at 8 it will reorganize by increasing the size of hashmap, at 64 it will convert to tree. I see value Min_treeify = 64. Also can you explain at what threshold it will convert back to linkedlist from tree.
If HashMap internally uses Hashtable, then how come it is accepting null key? because hashtable do not allow nulll values. My doubt is while inserting values inside hashmap, where they will get inserted? in hashtable or at that index of hashtable new linked is created?and first element is added in that list?
Hi Naveen, what if we want to get old value for duplicate keys? Is there any way we can get old value instead of the latest?
Hi Naveen, Why equals and hashcode implementation is required for the key and value both if this is needed only for the key..
hashcode and equals methods implementation is required for key not for value.
In linked hashmap collision occurs ah Naveen
Just FYI , Answer for 10 ) one is Yes , we can have duplicate values with different keys
Sir, could you please clear the concepts of IO ad NIO package in Java.
It would be very helpful.
Can you sort HashMap in java? I feel answer is yes. As we can sort it according to keys or values also. Like below for sort it accordingly to keys.
public class SortedHashMap {
public static void main(String[] args) {
HashMap hm = new HashMap();
hm.put(2, "B");
hm.put(1, "A");
hm.put(4, "D");
hm.put(3, "C");
Map sortedMap = hm.entrySet().stream().sorted((a,b) ->a.getKey().compareTo(b.getKey())).collect(Collectors.toMap(Entry::getKey, Entry::getValue,(e1,e2) ->e1));
System.out.println(sortedMap);
}
}