Note that String.substring()
implementation and the actual implementation of String
has changed with Java 7 (release 6, IIRC)
So depending on your Java version:
- if it's post Java 7u6, you can't do this.
String.substring()
will give you a completely new string
- if it's an older version of Java, you could access the private underlying char array of your new
String
, and this is in fact the complete char array of your old string
Item 2 is particularly nasty, and I suspect beyond what you really want to achieve.
See here for more details behind the substring() implementation and how it's changed.