How many people were struck by Java substring memory issues?

I recently discovered that the java.lang.String.substring method does not return a new string, but is the original string, which was subscript. This may have memory implications. For example, if you read the ascii file and parse the tokens in the file using a substring and store the result of the substring in memory somewhere - what you actually save in memory is a whole line before the substring operation! You can, of course, solve this by wrapping the substring in your own version, which returns a new line of the substitution result.

+3
source share
3 answers

, . , , BufferedReader, , 80- char.

, :

word = new String(word);

, , , , " ".

+11

2000 2001 XML ( , ) . , , , 3 FpML ( XML, ).

, ,

String copy = new String(s);

IntelliJ IDEA , ! IDE.

+1

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

The java docs indicate that the substring method returns a new line.

Or did I misunderstand the question?

In addition, strings are immutable. Here's an SO stream that explains why this is.

0
source

Source: https://habr.com/ru/post/1711147/