I have a few questions about strings which are doing my head in. I am trying to understand the difference between the following two expressions
Based on this article
http://www3.ntu.edu.sg/home/ehchua/programming/java/J3d_String.html , in the first example a
string object will be created on heap and a reference to it is placed in the string pool. In the second example, a String Object is placed on the heap but i am not clear as to whether a reference to it is added to the pool.
I tried a simple tests as shown below but the output confused me even more
The output of the above program is
* Why does the result of s1==s2 change depending on whether the output is concatenated to a String?
* since s1 == s4 is false, does that mean that strings created using the new keyword are not placed in the pool?
* If the above is true, does that mean that strings created using the new keyword are NOT immutable?
i am seeing confusing descriptions in other places. Some say two objects are created when you use "new" some say only one.