Hacker News new | past | comments | ask | show | jobs | submit login

>String.substring in Java does exactly that.

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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: