Jesper de Jong wrote:
When you have a very long string (for example you read the contents of a file into a String object) and you take a substring out of it, then the JVM will retain all the data of the original string in memory - even if you discard the original String object, because the String object created with substring() still holds a reference to the whole character array with all the data.
John de Michele wrote:
pete stein wrote:But wouldn't it then not be a constant?
Not necessarily. Static means that the variable or reference would be associated with the class, and not an individual object. Making the variable or ref final would mean that you could have a constant for each object.
Henry Wong wrote:Abhishk, it is generally *not* a good idea to give "read made solutions" -- as the JavaRanch is a learning site, and there isn't much learning when you are given the answer.
Henry Wong wrote:
If you want to attempt a regex solution, I would recommend that you look at the find(), appendReplacement(), and appendTail() methods. The replaceAll() method is a bit too high level to do this operation efficiently (meaning it won't be able to do this in a single pass).