• 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

Doubt in collection

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


which produces something like this:
Dog@1c
DOG
CAT key
Dog key
null
5

If we add two lines of code to the end of the earlier MapTest.main(),

d1.name = "magnolia"
System.out.println(m.get(d1));

we get something like this:
Dog@4
DOG
CAT key
Dog key
null
5
null

I am really confused why the output is "null" after setting d1.name="magnolia", I suppose the output should be "Dog key". I have compiled this code but still confused how it is working.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes, it should print Dog Key and it does... I tried..
Guess you just forgot to save the changes before compiling again

Regards,
Vishwa
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
murthy are you sure??
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sridhar,

After adding those lines,




I'm pasting the o/p:

Dog@4
DOG
CAT key
Dog key
null
5
Dog key

 
sridhar row
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Murthi, my bad ..my hashcode was returning name.length() which would be different for different names hence i was getting null..sorry abt the confusion.
reply
    Bookmark Topic Watch Topic
  • New Topic