Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on HashSet

 
wong sheena
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is a Question from K & B pg 630.
I'm wondering why duplicate entry is allowed.
At first I thought it is because of the equals() and hashCode().I have added as well. Have I left out something??
Thanks in advance!
 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, change harshCode() to hashcode().

Then print out the returns of add() to see the duplicate ones are failing.



I get the following result:
 
wong sheena
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, change harshCode() to hashcode().

YeaH should be hashCode(). hehe.. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic