The moose likes Java in General and the fly likes Overriding equals() & hashcode() in collections Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Overriding equals() & hashcode() in collections" Watch "Overriding equals() & hashcode() in collections" New topic
Author

Overriding equals() & hashcode() in collections

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear all,
What is the need for overriding equals() & hashcode() in Collections .
Normally every instance by default inherits Object class which has equals() & hashcode() . Then why we should override it?
Regards.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32704
    
    4
java NameDemo ramya ramya

See what comes out. You need to have two identical objects recoognised as identical to each other for the Collections to work.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Overriding equals() & hashcode() in collections
 
Similar Threads
HashCode Call
hashcode
Regarding equals method
HashCodes
equals() and hashCode() required to override for class used in Map key