why the hashCode is same for str1 and str2?
map--{a1=1, a2=2, a3=3, a4=4}
str1 hashcodee-1424385949
str2 hashcodee-1424385949
str3 hashcodee-1206291387
gurpsbassi
When you say 8th bucket, how do you know its gone into the 8th bucket?
bucket is not the same as the position in the hashmap. A bucket is a collection of entries.
What all single digit string, 2digit string (like AA, DC, ZX etc) , 3 digit string like (AAA, FRG,EWA etc) have same hash?
Any program for that to find? what percentage times these hash values are equal?
please advise
The put method internally uses the hashcode of the object and calculates the hash and indexFor to find the bucket number.
It has inserted in bucket 9. When you use containsKey function , it uses the hashing functionality to find the bucket number.
About bucket selection i see link explained about containsKey and put methods which decides whether 9 or 8th bucket. I was not clear on that. can you please advise more that?
CEHJ
The best way to understand Java maps is to study the source code. e.g. java.util.HashMap
When you say 8th bucket, how do you know its gone into the 8th bucket?
bucket is not the same as the position in the hashmap. A bucket is a collection of entries.
as attached i see 8. Not sure if it is position of hashmap or bucket. I guess i am thinking both as same. I wonder how bucket and position are different. please advise HashMapQuestions.png
CEHJ
The bucket starts as the tail of a linked list of HashMap.Entry
gudii9
ASKER
8 shown in HashMapQuestions.png screenshot is bucket number or position of hash map?
Open in new window
why the hashCode is same for str1 and str2?
map--{a1=1, a2=2, a3=3, a4=4}
str1 hashcodee-1424385949
str2 hashcodee-1424385949
str3 hashcodee-1206291387