File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on HashSet

 
wong sheena
Greenhorn
Posts: 23
  • 0
  • 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
  • 0
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, change harshCode() to hashcode().

YeaH should be hashCode(). hehe.. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic