I have a question about address of object in JAVA.
the following is my code.
public class StringCompare {
public static void main(String[] args) {
String s1 = "apple";
String s2 = "apple";
String s3 = new String("apple");
boolean b1 = (s1 == s2);
boolean b2 = (s1 == s3);
boolean b3 = s1.equals(s2);
System.out.println(b1); // true
System.out.println(b2); // false
System.out.println(b3); // true
System.out.println("");
System.out.println("Address of s1 = " + Integer.toHexString(s1.hashCode())); // 58b835a
System.out.println("Address of s2 = " + Integer.toHexString(s2.hashCode())); // 58b835a
System.out.println("Address of s3 = " + Integer.toHexString(s3.hashCode())); // 58b835a
}
}
I think address of object(s1 and s2) is same.
I think Address of object(s3) is not equal to s1, s2.
but.. result is address of object(s1, s2, s3) is same.
I don't know why s1, s2, s3 address is same..
Please give me some advice.
Thanks.