Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding equals() & hashcode() in collections  RSS feed

 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54033
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!