HashMap Performance when overriding hashcode method

后端 未结 5 977
悲&欢浪女
悲&欢浪女 2021-02-06 10:34

In a HashMap, if I put custom objects as a key.

What would happen if I override hashCode() method and implement it to pass value as \'1

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 11:07

    Adding Math.random() doesn't affect much performance hit but it is a bad idea to construct hashcode values through random() function. Instead you can use some of the good hashing function to minimize the collision and which are much faster also. For reference you can check out some of the links http://www.partow.net/programming/hashfunctions/

提交回复
热议问题