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();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For the
hashCodeof anintthe most natural choice is to use theintitself. A better question is what to use for thehashCodeof alongsince it doesn’t fit into theint-sized hashcode. Generally, your best source for that—and allhashCode-related questions—would be Effective Java.Here’s what Effective Java recommends (and the JDK uses) for the
longtype: