.equals and "==" WHY ?

String s1 = "String";String s2 = "String";System.out.println(s1.equals(s2)); //Returns TrueSystem.out.println(s1==s2); // Also returns True// Is this correct ? why ?// == compares by mem add right ? meaning those to Strings have the same memory address ?
[296 byte] By [Itachi_Uchiha_Go] at [2007-9-30 17:34:33]
# 1

Yes. Literal strings with the same value always refer to the same object, so s1 and s2 reference the same object in the same memory address. To create a new string object you would use the new-operator: String s = new String("abc");

http://www.janeg.ca/scjp/oper/string.html

this subject has been discussed to death in these forums, see e.g. http://forum.java.sun.com/thread.jsp?thread=540218&forum=31

jsalonen at 2007-7-6 13:57:53 > top of Java-index,Administration Tools,Sun Connection...