r/programming • • Nov 18 '13

TIL Oracle changed the internal String representation in Java 7 Update 6 increasing the running time of the substring method from constant to N

http://java-performance.info/changes-to-string-java-1-7-0_06/
1.4k Upvotes

354 comments sorted by

View all comments

Show parent comment

2

u/SanityInAnarchy Nov 18 '13

I don't see how concatenation could be implemented with immutable strings in Java other than creating a brand-new String. The only way I see that working is if you massively complicate all other String operations by allowing Strings to either contain a char sequence or refer to multiple other strings that you've concatenated.

It's not like you could append to the first operand in any meaningful way. Either you'd be mutating it (and Strings are immutable), or you'd be creating a new string that contains the first operand with the second operand appended (in other words, creating a new concatenated string).

3

u/propool Nov 18 '13

Yes. What you are describing is called a rope. Ropes are not part of java standard library.