Originally Posted by
aussiemcgr
The code for the substring method actually isn't that nice. What the substring method "really" does is create a new String object which references the same literal String in memory, but adjusts some pointer indexes or something. It's not as cut-and-dry as you'd expect it to be.
Indeed. Sorry for the self-promotion, but I wrote an article a while back that describes
when to construct a new String object, and goes into detail about what goes on under the hood of this class, using the Reflection API to demonstrate this behavior.