when I tried addding duplicate elements to those classes , it worked fine. There was no error
How can I ensure that only unique elements are added to my set ?
Anbarasu Aladiyan
jose chiramal wrote:However when I tried addding duplicate elements to those classes , it worked fine. There was no error .
How can I ensure that only unique elements are added to my set ?
Also, what do these equals and hashcode methods actually do, since its only because of these two methods that the output is not showing any duplicates in HashSet. I have understood the impact of using/not using equals and hashcode, but not able to understand what these methods actually do
jose chiramal wrote:1. Which classes override the equals and hashcode methods. Is it only String and Wrapper Classes or are there other classes.
jose chiramal wrote:2. How does overriding equals() and hashcode() actually help in NOT DISPLAYING the duplicate values ?
Am really trying to understand "whats so special" about the equals and override() methods.
Consider Paul's rocket mass heater. |