• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question in Map

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic