0

I found this post on stackoverflow that Double in HashMap states:

I was thinking of using a Double as the key to a HashMap but I know floating point comparisons are unsafe

But I can't really find out why it is unsafe to use doubles as key in your hashmap. Could you guys explain that to me?

Community
  • 1
  • 1
hY8vVpf3tyR57Xib
  • 3,184
  • 5
  • 38
  • 80

1 Answers1

1

in simple words the key you are using for map, will be changed very much for even a small decimal change in fractions, the probability of missing the values is much higher.

hashCode of java.lang.Double says (int)(v^(v>>>32))

prsutar
  • 425
  • 2
  • 4
  • 17