To add to Ratuls explanation,
new String objects are created if the above string operations change that string. And thats because Strings are immutable.
so if u say
String s1 = "Funny";
String s2 = s1.trim();
s1 and s2 are still at the same memory location ecause trimming has yielded the same string and so why waste a new memory chunk to store that.
This has more to do with how
java compiler tries to optimize things. But honestly, in a real life situation, i guess, one need not use == and should always use .equals() only.
Any objections?
Vivek