Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
Members have full access to the forums. Advertisements are removed for registered users.
Last edited by helloworld922; September 6th, 2010 at 12:48 AM.
In both cases it's actually calling the toString() method. The default toString method for objects is to append the class name followed by the hashCode (default is the memory address).
For obvious reasons, the String toString() method returns itself. However, the String class also overrides the hashCode() method so there's no easy way to retrieve the memory address of the string (I don't think it's possible without using JNI).
The larger question is why would you want to know the memory address of strings? In Java, you can't manually modify this value, except by setting it to a "valid" object of that type or null.
I wanted to know the address for the reason that :
I understand why it's false in the first case. If it's true in the second then what is true (is it the address?)
what is there at the addresses of s1 and s2 ?
Last edited by helloworld922; September 6th, 2010 at 04:27 PM.
For object equality, you should be using the equals as opposed to equality with '==', which is more for primitives. Using your example:
Last edited by copeg; September 6th, 2010 at 03:24 PM.
American (September 6th, 2010)