I have developed one application which can using hashset concept. I have to override the equals(), hashCode() and toString() methods in hashset. I dont know exactly why to override the given methods. Kindly anyone tell me what happen without override the above methods.
I have developed one application which can using hashset concept. I have to override
Share
For example read this:
http://www.javamex.com/tutorials/collections/hash_code_equals.shtml
There is plenty of discussions about the subject elsewhere (I recommend Effective Java book).
You do not need to override toString(), it’s a bonus.
Basically if you don’t override equals, you will not be able to get things from the collections the way you would expect. E.g. if your String class didn’t have equals implemented in a meaningful way, collection.get(“abc”) and collection.get(new String(“abc”)) would give you different results.