File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question in Map

 
Mebi Mathew
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 316
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic