jQuery in Action, 2nd edition*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on HashSet" Watch "Question on HashSet" New topic

Question on HashSet

wong sheena

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

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
A Generics and Collections Problem
Correctly override equals and hashcode
K&B Chapter 7 Question # 12