aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Issue in Working with Maps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Issue in Working with Maps " Watch "Issue in Working with Maps " New topic
Author

Issue in Working with Maps

Maheswaran Devaraj
Ranch Hand

Joined: Sep 14, 2007
Posts: 47
Hi friends,



In the above code the marked line 7 also giving the null, I don't know why it is giving null, because I have defined
both the hashcode and equlas method in the Dog class.

Thanks in Advance,
Mahes
Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
The culprit here is line 52, in which you are changing the name of d1 object. So when you try to retrieve from map the hashcode method will return different value since the name is changed and hence desired object will not be found.


My Techie Blog - Java Questions
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3257
It is a best practice to use immutable obejcts as your key. You can use the Wrapper classes.


500+ Java Interview Questions and Answers | Java job hunting know how & Java resumes
 
wood burning stoves
 
subject: Issue in Working with Maps