• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

doubt in hashMap kathy seirra ocjp 1 & 2 study guide

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks..i am new in learning collections. Unable to get how Map works with key value pair...i am unable to get this example


i am unable to get how values are retrieved using hashcode..somehow i was able to get answer..but it was guess..I am not sure correct way how get method finds value..
i understood that new Cat() gives null because equals and hashcode not overridden...

i am also unable to get..how this code when added at the end of main method produces following output



i just know use hashcode to find correct bucket and equals to find object.but practically how it works unable to get..

thanks

regards akshay
 
author
Posts: 23931
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akshay Rawal wrote:
i am unable to get how values are retrieved using hashcode..somehow i was able to get answer..but it was guess..I am not sure correct way how get method finds value..



It would help if you tell us, what were the results, what were your guesses, and what is still confusing you. We can't read your mind, hence, we can't say if you are right or wrong.

Akshay Rawal wrote:
i am also unable to get..how this code when added at the end of main method produces following output



i just know use hashcode to find correct bucket and equals to find object.but practically how it works unable to get..



In this case, the key of a hashmap must not be mutated. If it is, the behavior is undefined (as it is a broken scenario). Since the behavior is undefined, we can't really say what should happen.

Henry
 
reply
    Bookmark Topic Watch Topic
  • New Topic