Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared.
Originally posted by Jeffrey Hunter:
So, in the above case, "lostReference" will essentially be lost in memory (assuming no other references point to it), until the garbage man comes along and cleans it up.
here will be TWO String object in the heap??
and Will String objects in the heap be Garbage collected if there is no reference refer to them?