String#substring creates a "view" onto the original string backed by the same byte[]. It would be nice if more of the extracted strings could just be views backed by the original full input.
The difficulty is that String internally uses byte[] not char[] (any longer). Also it is not possible to wrap an existing char[] or byte[] into a String instance without copying it entirely or a section of it. This means most likely sharing can only be done by changing from String to CharSequence in the places that expose shared content.
String#substringcreates a "view" onto the original string backed by the samebyte[]. It would be nice if more of the extracted strings could just be views backed by the original full input.The difficulty is that
Stringinternally usesbyte[]notchar[](any longer). Also it is not possible to wrap an existingchar[]orbyte[]into aStringinstance without copying it entirely or a section of it. This means most likely sharing can only be done by changing fromStringtoCharSequencein the places that expose shared content.