• Post Reply Bookmark Topic Watch Topic
  • New Topic

about hashCode reliability  RSS feed

 
Arto Pastinen
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Have you people ever think that how reliable java's hashCode actually is if hashCode is generated from String by VM's default implementation..

I have think that if i have a map, where i put host names, is it possible that two different host name gives same hashCodes?!? i think

Let's think that we are using unicode charset (not for host's but some other case), and unicode character length is 16 bit, and hashCode is 32 bit length, so we can actually use only two character as key until all possibilies are used..

Please give me comments if i am wrong..

- Artsi
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have think that if i have a map, where i put host names, is it possible that two different host name gives same hashCodes?!? i think

Read the JavaDocs for java.lang.Object hashCode method. There you will find a strongly made point that different objects are not required to create different hashcodes.
Next - read the actual source code for java.lang.String hashCode method.
(Thats one of the great things about Java IMHO - you get the source code for the standard library and can consult it when questions like this come up.)
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!