▲ | grogers 5 days ago | |||||||
Also, you can't construct a java String without copying the data into it, because String is immutable. In other languages like c++ or rust the string type is mutable so you don't need an extra copy. Java doesn't even special case blessed APIs like StringBuilder to avoid the extra copy, since StringBuilder itself doesn't have a method to consume the inner buffer, you can only create a string from it without touching the buffer even though it's not the normal usage to create multiple strings from a given StringBuilder. | ||||||||
▲ | throeaway9 4 days ago | parent [-] | |||||||
For cases where a string repeats itself, you can use String.intern() to reuse data. | ||||||||
|