How does substring
method work internally and how can it create memory issue ?
How can we solve it?
How does substring
method work internally and how can it create memory issue ?
How can we solve it?
Prior to Java 7 udate 6, substring
used to return a view on the original string. So imagine you had a String of 1,000,000 characters and called s.substring(0, 1)
because you are only interested in the first character, the original string would have stayed in memory.
Since Java 7u6 substring
returns a new string which prevents that issue.