Hi All,
Am I understanding this right?
The String-constant-pool is in heap memory.
String s = �abc� ;
Creates a String literal �abc� in the String-constant-pool with s referencing �abc�.
String s1 = �abc� ;
No new String literal is created. s1 is simple referred to the already existing �abc� in the pool.
String s2 = new String( �abc� ) ;
A new String object �abc� is placed on the heap. No new String literal �abc� is put in the pool since �abc� already exist. s2 references the String object �abc� on the heap, but not the String literal �abc� in the pool.
String s3 = new String( �xyz� ) ;
A new String object �xyz� is placed on the heap and a String literal �xyz� is put in the pool. s3 references the String object on the heap, but not the String literal in the pool.
String s4 = new String( �xyz� ) ;
Another, different, String object �xyz� is placed on the heap. The if ( s3 == s4 ) fails. Again no new String literal �xyz� is put in the pool since �xyz� already exist. s4 references the String object �xyz� on the heap, but not the string literal �xyz� in the pool.
One last thing. Why doesn�t, �System.out.println( s1 + � and � + s3 ) ; � create new Strings without references? Wouldn�t the following Strings be created? � and � for one String. �abc and � for a second String. �abc and xyz� for a third String.
Thanks,
Richard