Hashcode of an int

后端 未结 4 1220
[愿得一人]
[愿得一人] 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条回答
  •  萌比男神i
    2020-12-09 03:35

    The java.lang.Integer.hashCode() method returns a hash code value for primitive value of int but represented as an Integer object.

    /**
     * Returns a hash code value for an Integer,
     * equal to the primitive int value it represents.
     */
    public class IntegerDemo {
    
        public static void main(String[] args){
            Integer i = new Integer("20");
            System.out.println("Value = " + i.hashCode());
        }
    
    }`
    

    Results:

    Value = 20

    Source Link: http://www.tutorialspoint.com/java/lang/integer_hashcode.htm

提交回复
热议问题