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 Using HashMap Problem 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 "Using HashMap Problem" Watch "Using HashMap Problem" New topic
Author

Using HashMap Problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

KB book





1.what does d1.name does ?

2.can anyone explain why
#1 gives complie-time error
#2, works fine
#3 gives complie time error

3.
In the last line of code,

The complier is comparing arthur length with clover length.
my question is why is it not comparing the length of name clover passed in the object (new Dog("clover") with that kept in the hashmap.

the hashmap holds d1 with Dog key
where d1 is the key and Dog Key is the value.
here d1 is


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Please QuoteYourSources.


[My Blog]
All roads lead to JavaRanch
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Change the name length of d1 and check....Like this....


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

see the changes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using HashMap Problem
 
Similar Threads
HasMap Problem using equals ANd hashCode methods
Using object as keys in maps
Doubt in MapTest example given in K&B
hashmap with duplicate key.
equal() & hashcode()