Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Since you can able to see the code written and executed line by line during this video, I would strongly recomment you to start write the same code in your eclipse and add the breakpoint as necessary and then run the code in debug mode. Let me know if you have any questions, we will help you out at the earliest. Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share with your friends. th-cam.com/users/RedSysTech
Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share with your friends. th-cam.com/users/RedSysTech Thanks & Regards, RedSysTech Team.
Hi, Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Thanks & Regards, RedSysTech Team.
Hi @Sujith, Thanks for the feedback! Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is quick link to share.. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Happy learning at #RedSysTech
Thank you for the feedback! Really Appreciate your comments!!! It's means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Regards, RedSysTech.
Thank you for the feedback! Really Appreciate your comments!!! It's means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Regards, RedSysTech.
Hi Sridar, Thanks for the feedback! Really Appreciate your words!!! It's means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/users/RedSysTech Thanks & Regards, RedSysTech Team.
Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Thanks & Regards, RedSysTech Team.
Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Regards, RedSysTech Team.
Hello sir, if we add two times null value to set. the index will be 0 obviously.it will be verifying with .equals() method right. then why we are not getting null pointer exception?
Hi there, Here you go... You're absolutely right about null being a tricky case with HashSet in Java. Here's why you don't get a NullPointerException when adding null twice to a HashSet: Understanding HashSet and equals(): HashSet uses a hashing mechanism to store and retrieve elements. While adding an element, it calculates a hash code based on the object's equals() method. This hash code is used to determine the bucket where the element will be stored. However, the equals() method is not called during the initial addition of null to the set. Why No NullPointerException? Sets, including HashSet, don't allow duplicate elements. When you add the first null to the set, it calculates a hash code for null (which is always the same) and stores it in the appropriate bucket. Since null itself doesn't have an overloaded equals() method, it's not invoked during the first addition. When you add the second null, the same hash code is calculated, and the set checks if an element with that hash code already exists. Because the first null is already present, the set simply doesn't add the second null. It recognizes it as a duplicate based on the hash code, even though equals() isn't called in this case. Hope this is clear to you now and helps! Please reach to us in what's app at +91-6383-787-989 for any further questions or clarifications required. Regards, RedSysTech Tech Support Team.
Thank you for the feedback! All the best for your carrier. Really Appreciate your comments!!! It's means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html Regards, RedSysTech.
Here how hashcode call internally based on what formula it will give the hascode and if hashcode will return same what will happen. Can you please answer my question if you get a free time
Hello Java Aspirant! Here is the detailed explanation. I tried my best to answer both of your questions. In a HashSet, the hashCode method is used to determine the bucket (index in the internal array) where an element will be stored. The general idea is to distribute elements across buckets evenly to achieve efficient insertion, removal, and retrieval. Here are the key points regarding the hashCode method and its interaction with HashSet: When you add an element to a HashSet, the hashCode method of the object is called to obtain a hash code. The hash code is then processed (typically by applying a supplemental hash function) to ensure a more uniform distribution across the buckets. The processed hash code is used to calculate the index (bucket) in the internal array where the element will be stored. This index is usually determined by taking the modulo of the hash code with the current capacity of the array. If two different elements have the same hash code (a collision), they will end up in the same bucket. HashSet handles collisions through a mechanism called chaining. Each bucket is implemented as a linked list of elements that share the same hash code. When you add an element to a HashSet, the hashCode method of the object is called to obtain a hash code. The hash code is then processed (typically by applying a supplemental hash function) to ensure a more uniform distribution across the buckets. If a new element has the same hash code as an existing element in a bucket, it is added to the linked list at that bucket. Once elements are in the same bucket, their equality is checked using the equals method to ensure that the HashSet only stores unique elements. If equals returns true for any two elements in the same bucket, the HashSet assumes they are equal and treats them as duplicates. As elements are added and the load factor increases (the ratio of the number of elements to the capacity of the array), HashSet may decide to resize and rehash the internal array to maintain efficiency. During rehashing, the elements are redistributed into a larger array, and the hashing process is applied again based on the new capacity. Hope this clarifies! Please let us know if you still having any questions regarding this concept! Always welcome to RedSysTech family!! Thanks, RedSysTech team.
Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Here is the answer for you:- In Java, we have the concept called threshold in HashMap. It's just thee current capaciity and thee load factor. This is nothing but whenever the capacity fo your hashmap reaches 12th (key-value pair) element, it increase it's capaccity internally from 16 to 32. This is exactly you are watching in this video as well. Hope this helps!!! Please share it with your friends. Since you can able to see the code written and executed during this video, I would strongly recomment you to start write the same code in your eclipse and add the breakpoint as necessary and then run the code in debug mode. Let me know if you have any questions, we will help you out at the earliest. Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share with your friends. th-cam.com/users/RedSysTech
Hello Java Aspirant! Here is the detailed explanation for the remove method in hashset. The remove method in a hash set involves applying the hash function, finding the index, and then handling any collisions that may have occurred during insertion. The exact details of collision resolution depend on the specific implementation of the hash set (chaining, open addressing, etc.). Also, the remove method in a hash set is used to delete an element. The steps involved in the removal process are as follows: 1. Apply the hash function to the element to determine its hash code. 2. Use the hash code to find the index in the array. 3. If the element is found at the computed index, remove it. 4. If there are multiple elements in the same bucket (due to collisions), the hash set needs to search through those elements to find and remove the specific element. Hope this clarifies! Please let us know if you still having any questions regarding this concept! Always welcome to RedSysTech family!! Thanks, RedSysTech team.
Hi Karthick, Thank you for the feedback! Really Appreciate your comments!!! It means a lot for us... Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends.. Here is the quick link to share. th-cam.com/users/RedSysTech As you know, HashSet is a class which implements Set interface. As per the language design, Set won't allow duplicates, which means when you try to add a duplicate to a set, the duplicate is simply ignored, and the set remains unchanged. Also, this does not lead to any compile or runtime errors. in other words, the duplicates are silently ignored. This is the underlying reason that HashSet is NOT allowing duplicate insertion. As explained in this video, When you call add(E e), method of set, it internally call put(E, e) method of HashMap which looks something like this : public boolean add(E e) { return map.put(e, PRESENT)==null; } Hence, the element you are adding to set/HashSet, is internally added to Map as a key. As we need to associate some value with the key in so dummy value(new Object()) PRESENT is passed every time (as Map can contain more than one duplicate values ). Now if you closely examine the return map.put(e, PRESENT)==null; of add(e, E) method. There can be two possibilities : if map.put(k,v) returns null ,then map.put(e, PRESENT)==null; will return true and element will be added. if map.put(k,v) returns old value for the key ,then map.put(e, PRESENT)==null; will return false and element will not be added. Hope this helps!!! Thanks & Regards, RedSysTech Team.
Graeat hat's off.......❤
Wow..... Nice good presentation clearly explained :)
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Since you can able to see the code written and executed line by line during this video, I would strongly recomment you to start write the same code in your eclipse and add the breakpoint as necessary and then run the code in debug mode. Let me know if you have any questions, we will help you out at the earliest.
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share with your friends.
th-cam.com/users/RedSysTech
Impressed 😀
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share with your friends.
th-cam.com/users/RedSysTech
Thanks & Regards,
RedSysTech Team.
You are best Sir
Hi,
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Thanks & Regards,
RedSysTech Team.
Wishing all the very best for RedSysTech
Hi @Sujith,
Thanks for the feedback! Stay tuned for upcoming more videos!!! Kindly Share our videos and Channel with your friends..
Here is quick link to share..
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Happy learning at #RedSysTech
super sir,,
Thank you for the feedback! Really Appreciate your comments!!! It's means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Regards,
RedSysTech.
Nice explanation tq anna
Thank you for the feedback! Really Appreciate your comments!!! It's means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Regards,
RedSysTech.
neatly explained..all the very best for future videos
Hi Sridar,
Thanks for the feedback! Really Appreciate your words!!! It's means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Good explanation sir 👍
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/users/RedSysTech
Thanks & Regards,
RedSysTech Team.
pretty clear explanation, only one thing lower the noise of notification bell at the end volume is too much
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Thanks & Regards,
RedSysTech Team.
thank you
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Regards,
RedSysTech Team.
Hello sir, if we add two times null value to set. the index will be 0 obviously.it will be verifying with .equals() method right. then why we are not getting null pointer exception?
Hi there,
Here you go...
You're absolutely right about null being a tricky case with HashSet in Java. Here's why you don't get a NullPointerException when adding null twice to a HashSet:
Understanding HashSet and equals():
HashSet uses a hashing mechanism to store and retrieve elements.
While adding an element, it calculates a hash code based on the object's equals() method. This hash code is used to determine the bucket where the element will be stored.
However, the equals() method is not called during the initial addition of null to the set.
Why No NullPointerException?
Sets, including HashSet, don't allow duplicate elements.
When you add the first null to the set, it calculates a hash code for null (which is always the same) and stores it in the appropriate bucket.
Since null itself doesn't have an overloaded equals() method, it's not invoked during the first addition.
When you add the second null, the same hash code is calculated, and the set checks if an element with that hash code already exists.
Because the first null is already present, the set simply doesn't add the second null. It recognizes it as a duplicate based on the hash code, even though equals() isn't called in this case.
Hope this is clear to you now and helps! Please reach to us in what's app at +91-6383-787-989 for any further questions or clarifications required.
Regards,
RedSysTech Tech Support Team.
Informative. Keep it up. Today my interviewer asked same question. That's Y I am here. :D
Thank you for the feedback! All the best for your carrier.
Really Appreciate your comments!!! It's means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/channels/AFbM5bjpV_eN-TZISuENcQ.html
Regards,
RedSysTech.
Here how hashcode call internally based on what formula it will give the hascode and if hashcode will return same what will happen.
Can you please answer my question if you get a free time
Thanks for asking a question! Will check out and respond back ASAP!
Hello Java Aspirant!
Here is the detailed explanation. I tried my best to answer both of your questions.
In a HashSet, the hashCode method is used to determine the bucket (index in the internal array) where an element will be stored. The general idea is to distribute elements across buckets evenly to achieve efficient insertion, removal, and retrieval.
Here are the key points regarding the hashCode method and its interaction with HashSet:
When you add an element to a HashSet, the hashCode method of the object is called to obtain a hash code.
The hash code is then processed (typically by applying a supplemental hash function) to ensure a more uniform distribution across the buckets.
The processed hash code is used to calculate the index (bucket) in the internal array where the element will be stored. This index is usually determined by taking the modulo of the hash code with the current capacity of the array.
If two different elements have the same hash code (a collision), they will end up in the same bucket.
HashSet handles collisions through a mechanism called chaining. Each bucket is implemented as a linked list of elements that share the same hash code.
When you add an element to a HashSet, the hashCode method of the object is called to obtain a hash code.
The hash code is then processed (typically by applying a supplemental hash function) to ensure a more uniform distribution across the buckets.
If a new element has the same hash code as an existing element in a bucket, it is added to the linked list at that bucket.
Once elements are in the same bucket, their equality is checked using the equals method to ensure that the HashSet only stores unique elements.
If equals returns true for any two elements in the same bucket, the HashSet assumes they are equal and treats them as duplicates.
As elements are added and the load factor increases (the ratio of the number of elements to the capacity of the array), HashSet may decide to resize and rehash the internal array to maintain efficiency.
During rehashing, the elements are redistributed into a larger array, and the hashing process is applied again based on the new capacity.
Hope this clarifies! Please let us know if you still having any questions regarding this concept! Always welcome to RedSysTech family!!
Thanks,
RedSysTech team.
what will threshold value do
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Here is the answer for you:-
In Java, we have the concept called threshold in HashMap. It's just thee current capaciity and thee load factor. This is nothing but whenever the capacity fo your hashmap reaches 12th (key-value pair) element, it increase it's capaccity internally from 16 to 32. This is exactly you are watching in this video as well. Hope this helps!!! Please share it with your friends.
Since you can able to see the code written and executed during this video, I would strongly recomment you to start write the same code in your eclipse and add the breakpoint as necessary and then run the code in debug mode. Let me know if you have any questions, we will help you out at the earliest.
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share with your friends.
th-cam.com/users/RedSysTech
how hash set use remove method?
Will explain this in another video shortly! Plz stay tuned!! 👍
Hello Java Aspirant!
Here is the detailed explanation for the remove method in hashset.
The remove method in a hash set involves applying the hash function, finding the index, and then handling any collisions that may have occurred during insertion. The exact details of collision resolution depend on the specific implementation of the hash set (chaining, open addressing, etc.).
Also, the remove method in a hash set is used to delete an element.
The steps involved in the removal process are as follows:
1. Apply the hash function to the element to determine its hash code.
2. Use the hash code to find the index in the array.
3. If the element is found at the computed index, remove it.
4. If there are multiple elements in the same bucket (due to collisions), the hash set needs to search through those elements to find and remove the specific element.
Hope this clarifies! Please let us know if you still having any questions regarding this concept! Always welcome to RedSysTech family!!
Thanks,
RedSysTech team.
Why it is not inserting duplicates ?
Hi Karthick,
Thank you for the feedback!
Really Appreciate your comments!!! It means a lot for us...
Stay tuned for upcoming more videos!!!
Kindly Share our videos and Channel with your friends..
Here is the quick link to share.
th-cam.com/users/RedSysTech
As you know, HashSet is a class which implements Set interface. As per the language design, Set won't allow duplicates, which means when you try to add a duplicate to a set, the duplicate is simply ignored, and the set remains unchanged.
Also, this does not lead to any compile or runtime errors. in other words, the duplicates are silently ignored.
This is the underlying reason that HashSet is NOT allowing duplicate insertion.
As explained in this video, When you call add(E e), method of set, it internally call put(E, e) method of HashMap which looks something like this :
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
Hence, the element you are adding to set/HashSet, is internally added to Map as a key. As we need to associate some value with the key in so dummy value(new Object()) PRESENT is passed every time (as Map can contain more than one duplicate values ).
Now if you closely examine the return map.put(e, PRESENT)==null; of add(e, E) method. There can be two possibilities :
if map.put(k,v) returns null ,then map.put(e, PRESENT)==null; will return true and element will be added.
if map.put(k,v) returns old value for the key ,then map.put(e, PRESENT)==null; will return false and element will not be added.
Hope this helps!!!
Thanks & Regards,
RedSysTech Team.