- String s1="123";
- String s2="123";
- String s3=new String("123");
- String s4=new String("123");
- System.out.println(s1.equals(s2)); //ture
- System.out.println(s3.equals(s4)); //ture 因为String重写了Object的equals( )所以这里比较的是内容,而不是地址值所以结果都为true
复制代码“两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?”