Maha Anna's second result was the one I found surprising. I guess the thing is that while most of the time toString() creates a whole new String, it's not actually obligated to (not like the new String() constructor is). Within the String class Sun evidently decided it was easier to just return another reference to the current instance, since it already is a string. As demonstrated here:
Thanks for pointing that out, Maha. (Is that an appropriate nickname?)
Jim, I think i read that this also happens with String.toUpperCase(). If the string is already Uppercase only, the original reference is returned and no new string object is created.
May the Moose be with you.
Joined: Jan 30, 2000
And with String.trim() also...
Joined: Jan 31, 2000
I have tested the foll. methods of String class. For simplicity (and laziness also ) I have omitted the args for these methods. All these return the same String object ref( upon which the method is invoked )when the returned String's content is same as the original.(case sensitive) touppercase(),tolowercase(),toString(),substring(),concat(),trim(),valueOf(),replace() Jim, All call me Maha ,kind of pet name.. regds Maha anna
[This message has been edited by maha anna (edited March 02, 2000).]
subject: Probably you all know it already, but still..