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 = hasCode + num.hashCode();
}
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 = hasCode + num.hashCode();
}
Taken from the
Integer.class
source code:Where
value
is the value of the integer.For the
hashCode
of anint
the most natural choice is to use theint
itself. A better question is what to use for thehashCode
of along
since it doesn't fit into theint
-sized hashcode. Your best source for that—and allhashCode
-related questions—would be Effective Java.The
java.lang.Integer.hashCode()
method returns a hash code value for primitive value ofint
but represented as anInteger
object.Results:
Source Link: http://www.tutorialspoint.com/java/lang/integer_hashcode.htm
No
hashCode()
method for primitive typeint
available.Integer
is Wrapper class type andhashcode()
returns anint