• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

doubt in hashMap kathy seirra ocjp 1 & 2 study guide

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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: 23879
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic