Suppose I have a string
msg = "hello"
Now I get substring from string msg
like msg.substring(1,msg.length())
And storing that substring into msg
.
So msg
refers to new string. If the old string also remain in buffer of java and yes then how to access it?
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:
String.substring()
will give you a completely new stringString
, and this is in fact the complete char array of your old stringItem 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With