posted 23 years ago
I agree with:
----------------I only see two Strings being created, one in line 1, and another in line 3. line 2 and line 4 reference existing strings.------------------------------------
if you try:
public class Test{
public static void main(String[] args)
{
String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1;
s3 = s2 + "Pal";
s4 = s3;
if(s2 == s1)
System.out.println("s1 == s2");
if(s3 == s4)
System.out.println("s3 == s4");
}
}
the result would be:
s2 == s1
s3 == s4
which means only two objects were created.