Hashcode of an int

后端 未结 4 1229
[愿得一人]
[愿得一人] 2020-12-09 02:34

What is the hashcode of a primitive type, such as int?

for example, let\'s say num was an interger.

int hasCode = 0;

if (num != 0) {
  hasCode = has         


        
4条回答
  •  悲&欢浪女
    2020-12-09 03:16

    Taken from the Integer.class source code:

    /**
     * Returns a hash code for this {@code Integer}.
     *
     * @return  a hash code value for this object, equal to the
     *          primitive {@code int} value represented by this
     *          {@code Integer} object.
     */
    public int hashCode() {
        return value;
    }
    

    Where value is the value of the integer.

提交回复
热议问题