This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on HashSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on HashSet" Watch "Question on HashSet" New topic
Author

Question on HashSet

wong sheena
Greenhorn

Joined: Apr 07, 2007
Posts: 23


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

Joined: Aug 13, 2006
Posts: 178
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

Joined: Apr 07, 2007
Posts: 23
First, change harshCode() to hashcode().

YeaH should be hashCode(). hehe.. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on HashSet
 
Similar Threads
Another Generics question
K&B Chapter 7 Question # 12
Correctly override equals and hashcode
A Generics and Collections Problem