简体   繁体   中英

comparing hashcodes with equals method

How can i use a .equals method to compare to hashcodes?

   int index = key.hashCode() % internal.length;
    for(KeyValuePair i: internal){
        int x = i.key.hashCode() % internal.length;
        if(x.equals(index))

    }

(error int cannot be dereferenced)

Use Integer class instead of int to use equals or simply == for comparing int variables. Because equals method is used with objects only.

The equals() method provided by Object tests whether the object references are equal—that is, if the objects compared are the exact same object.

Use Integer class instead of int. Because equals method is used with objects only, cannot be used with primitives.

The equals() method provided by Object class tests whether the object references are equal—that is, if the objects compared are the exact same object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM