| Author |
hashmap with duplicate key.
|
jamil lusa
Ranch Hand
Joined: Aug 18, 2011
Posts: 58
|
|
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!
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Jamil did you try it out? What was the output when you tried it?
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
jamil lusa
Ranch Hand
Joined: Aug 18, 2011
Posts: 58
|
|
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.
|
 |
Alexandr Khomichenko
Greenhorn
Joined: Oct 13, 2011
Posts: 1
|
|
There will be duplication of keys. See the sample:
output: y y
|
 |
 |
|
|
subject: hashmap with duplicate key.
|
|
|