System的identityHashCode()

xiaoxiao2021-02-27  658

//对象的identityHashCode()相同,一定是相等的对象 public class IdentityHashCodeDemo { public static void main(String[] args) { String str1 = new String("Hello World"); String str2 = new String("Hello World"); System.out.println(str1.equals(str2));//true System.out.println(str1.hashCode()==str2.hashCode());//true System.out.println(System.identityHashCode(str1)+"====="+System.identityHashCode(str2));//值不同 String str3="Java学习之法"; String str4="Java学习之法"; System.out.println(System.identityHashCode(str3)+"====="+System.identityHashCode(str4));//值相同 } }
转载请注明原文地址: https://www.6miu.com/read-822.html

最新回复(0)