hi all,
As of my understanding hash set will not allow duplicates. But when I add two different object of same class with same value it is accepting, at the same time same object with different values are not accepting.Kindly clarify me
Senario-1
TestBean testBean = new TestBean();
testBean.setId(1);
testBean.setId(100);
HashSet<TestBean> hashSet = new HashSet<TestBean>();
hashSet.add(testBean);
testBean = new TestBean();
testBean.setId(1);
testBean.setId(100);
hashSet.add(testBean);
System.out.println(hashSet.size());
Senario-2
TestBean testBean = new TestBean();
testBean.setId(25);
testBean.setId(100);
HashSet<TestBean> hashSet = new HashSet<TestBean>();
hashSet.add(testBean);
testBean.setId(1);
testBean.setId(100);
hashSet.add(testBean);
System.out.println(hashSet.size());