Jesper de Jong wrote:
The constructor of class String that takes another String is useful in some special cases
SCJP6.0,My blog Ranchers from Delhi
ashwin bhawsar wrote:With 'new' operator new strings objects are created out of the string-pool, and they are eligible for garbage-collection. So if you don't need them anymore you can make the eligible for garbage collection, but the down side of this is that with 'new' operator JVM will always have to create a new object and it is an overload for JVM.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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.
There are only 10 types of people in the world: those who understand ternary, those who don't, and those who mistake it for binary.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jesper de Jong wrote:
If you want to see how exactly it works, then have a look at the source code of class String, which you can find in the file src.zip in your JDK installation directory.
Piyush
Piyush Joshi wrote:1. Am I getting it right that a native method intern() is called when we use a literal to initialize a String reference.
2. Javadocs for intern() method says : A pool of strings, initially empty, is maintained privately by the class String.
What does "privately" mean here? Is this pool maintained in native code?
Stephan van Hulst wrote:
2. Javadocs for intern() method says : A pool of strings, initially empty, is maintained privately by the class String.
What does "privately" mean here? Is this pool maintained in native code?
No, it really just means private. The String class keeps a private collection of Strings to keep track of which have been interned.
Piyush
