Double in HashMap

后端 未结 8 1214
借酒劲吻你
借酒劲吻你 2020-11-28 11:17

I was thinking of using a Double as the key to a HashMap but I know floating point comparisons are unsafe, that got me thinking. Is the equals method on the Double class als

8条回答
  •  自闭症患者
    2020-11-28 11:39

    The hash of the double is used, not the double itself.

    Edit: Thanks, Jon, I actually didn't know that.

    I'm not sure about this (you should just look at the source code of the Double object) but I would think any issues with floating point comparisons would be taken care of for you.

提交回复
热议问题