As in your video we can see HashMap while debugging the code but same way I am doing but unable to see HashMap after adding string value. please tell me where I am doing mistake.
Nice explanation but why it is implemented this way ? Is there any advantage of doing it this way ? And what is the use of the PRESENT object ? @Naveen
As u know set will not Store the duplicate value but did u ever though how exactly set will not Store the value that reason is set algorithm is written in such way that check if u are add the elements throughout the add method then internally ur source code interpret according to ur jdk inside classloader and it will call the specific for set library and then set algo library check in same way if u are not comfortable "Present" then u can take any variable and it is same work as a Boolean to check data is already present or not and u want see ur source code if u decompile there Present is available and if u want create ur own custom set then followed the same approach whatever for writen is set algorithm
Very well explained Naveen, however what I observed here, if HashSet not follow insertion order then why is it implementing SortedSet interface, I believe HashSet extends AbstractSet and implements Set interface. Please Advise if am wrong.
Nice Info but I unable to open that info while hover toggle point and display map then table , etc, the version I am using on windows won't provide that many details. Please provide some solution for this. Thanks
public class Emp{ int id; String name; //Constructor overrided with args public static void main(String[] args){ Emp e1=new Emp(1,"A"); Emp e2=new Emp(1,"A"); Emp e3=new Emp(1,"A"); Emp e4=new Emp(1,"A"); Set set= new HashSet(); set.add(e1); set.add(e1); set.add(e2); set.add(e3); set.add(e4); System.out.println(set); } } Please explain this scenarios When hashcode and equals both overrided or any one of them is overrided or none of them are overrided
When u add duplicate hashset simply ignore.. ignore in a sense that it is overwriting the previous value with new one. if i add "abc" again i add "abc" both are same value previous abc will be overwritten.
Yes, As It uses the same implementation of HashMap So If we continue on this then we can goto the Bucket Size, Collision Handling Balanced Binary Tree. Everything is same!