This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
All Strings are immutable. Once created they can NOT be modified in any way. This is to allow for some cute little "optimizations" in the JVM. Specifically the re-use of defined Strings. If you define the String "String yes = "Y"; in lots of places, the JVM only makes ONE object for it and points all the various uses at the same object. This is fine if you know that it can never change. However, if multiple uses are all pointing at the same String value - it would be catastrophic if one of the uses tampered with the thing. Instead there is a StringBuffer class for cases where you know that the object is going to change values.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: May 11, 2001
If you cannotate two strings and store the result in a new object, does the new object point to the old locations? Or, store the result of f and k? String f = "Bellis"; String k = "simo!"; String r = f + k; System.out.println(r); Bellissimo! Forget about it! Thanks Cindy, your the greatest.
Joined: Sep 29, 2000
A third object is made that r points to.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com