File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collections : Help Needed 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 "Collections : Help Needed" Watch "Collections : Help Needed" New topic

Collections : Help Needed

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 390
In K&B Book page -614, Question -7. I have 2 questions

1. Please let me know where is the explaination related to this question in present in the entire chapter.

2. If no hashcode() then each will go in it's own bucket, then no question of equal() comes into picture. But if hashcode present will duplicate keys (equals()) will be detected @ compile time or runtime. I think @ runtime . Please correct me if i am wrong.

Please put some more light on the expaination...

Thanks in advance.
Alina Petra

Joined: Oct 17, 2006
Posts: 26
1. I think that reading Using Maps section (page 563) would help.

2. t1.equals(t2) returns false because the hashCode() is not overriden, therefore the output will be 3.
But if the hashCode() is overriden, then t1.equals(t2) will return true, therefore the output will be 2.
I agree. Here's the link:
subject: Collections : Help Needed
Similar Threads
hashcode question
equal() and hashcode()..
Help me with equals! - I've exam tomorrow
hashCode() problem
TreeSet uses compareTo