• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

hashmap with duplicate key.

 
Ranch Hand
Posts: 59
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, good day everyone,

i am reading the K&b scjp 6 guide book, in this example:





after that i have read this section:



so obviously changing the hashcode-factor will affect the hashmap collection object (from the example above), now my question is
if the hashcode is changed, it is possible to get duplicated key, and what will happen since hashmap does not allow dulplicated key?

I have checked the hashmap API , the function 'put' will override/replace the duplicated value with the previous value. but how about the question taht i am asking? the collection has distinct key, but suddenly its hashcode has been changed. what happen to the collection?

Thanks , appreciate your reply!
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jamil did you try it out? What was the output when you tried it?
 
jamil lusa
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry i do have compiler in my office pc right now. if got, i have tried to compile it already.

i am using my spare time in office to learn scjp. hoho , hope not be caught by my boss.

this question is too tricky, i really cannot figure out.

hope this question is interesting enough, so there is someone may test it.

Good day,
Jamil.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There will be duplication of keys. See the sample:

output: y y
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic