wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question in Map 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 in Map" Watch "Question in Map" New topic
Author

Question in Map

Mebi Mathew
Greenhorn

Joined: Jul 19, 2010
Posts: 4
Hi

I am new to JavaRanch

Can anyone please explan the following code


The output of line 1 is raju
The output of line 2 is null.

My question is why line 1 is giving the output as raju
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Because

1. Your hashcode implementions allows for searching the same bucket.
2. Your equal method returns true as the compared object and object stored are referring to the same object.

If you do the following

Dog d= new Dog("arthur");
m.get(d);

then it would return null iff Orginal Dog's name has not been changed to "arthur".

Cheers!!!

SCJP 6.0 96%

(Connecting the Dots ....)
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

First, have a look on here, to know how the Map works!

Clue : Change the length of your Dog's name, then get the value pair with those objects! For example


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Question in Map
 
Similar Threads
Hashmap doubt from K&B
K & B - Generics & Collections
Please explain HashMap?
equal() & hashcode()
hashcode and equality