aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes hashmap with duplicate key. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "hashmap with duplicate key." Watch "hashmap with duplicate key." New topic
Author

hashmap with duplicate key.

jamil lusa
Ranch Hand

Joined: Aug 18, 2011
Posts: 59
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
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

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: 59
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hashmap with duplicate key.