http://blog.csdn.net/zhangerqing/article/details/8093919
The difference between hashcode and Identityhashcode
The I, Hashcode () method is a method under the object class that is overridden by the inheriting class, computes the hash value based on the object memory address, the string class overrides the Hashcode method, and instead computes the hash value based on the sequence of characters
The II, Identityhashcode () method is a static method in the system class that computes the hash value based on the object memory address;
Method Example:
-
Public Static voidMain (string[] args) {//S1 and S2 are two different objects in the following programString S1 =NewString ("Hello"); String S2=NewString ("Hello"); //The string class overrides the Hashcode method of the object class--instead calculates the Hashcode value based on the character sequence .//because S1 and S2 have the same sequence of characters, their Hashcode method return values are the sameSystem.out.println (S1.hashcode () + "----" +S2.hashcode ()); //S1 and S2 are different string objects, so their identityhashcode values are different,//Identityhashcode is calculated based on the address of the object, so any two different objects//Identityhashcode values are always unequalSystem.out.println (System.identityhashcode (S1) + "----" +system.identityhashcode (S2)); //S3 and S4 are the same string objects, so their identityhashcode values are the sameString s3 = "Java"; String S4= "Java"; System.out.println (System.identityhashcode (S3)+ "----"+System.identityhashcode (S4)); }
Output:
Java-se-interview (1)-string