Not since 2007 (java 7).
The extra ints (8bytes) used for marking the beginning/end of the string and the fact the subscring leaked the ref. to the original string caused extra memory footprint. So now it's just a copy unless the substring is exactly the same as the original.
Previously (around 2004) I used to call new String(string.substring) in specific cases to prevent leaks.
>Is there any other way that can be done? <-- yes copies.
Not since 2007 (java 7). The extra ints (8bytes) used for marking the beginning/end of the string and the fact the subscring leaked the ref. to the original string caused extra memory footprint. So now it's just a copy unless the substring is exactly the same as the original.
Previously (around 2004) I used to call new String(string.substring) in specific cases to prevent leaks.
>Is there any other way that can be done? <-- yes copies.