If the code mentioned below is run "true, true, true" is displayed.
If the strings are immutable then different instances of String objects will be created on each of the call of s0.trim() etc.
Why the comparison is same even if the references are different?
public class Test012
{
public static void main(String args[])
{
String s0 = new String("Java");
String s1 = s0.trim();
String s2 = s0.substring(0, 4);
String s3 = s0.toString();
System.out.println(s0 == s1);
System.out.println(s0 == s2);
System.out.println(s0 == s3);
}
}