Javadoc says for public String substring(int beginIndex)
:
"Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex."
The length of "apple" is 5, so the length of x.substring(5)
is 5 - 5 == 0.
On the other hand the api doc says that if
"... endIndex is larger than the length of this String object ..." the exception you experienced is thrown. For x.substring(6)
your endIndex is 6 while the length of the String object is 5.
You are asking "Is there some kind of empty string that can be referenced appended to every string?". I would say yes, that's true in some way: the empty string is 'contained' at any position of any string, and it can be appended to any string without changing it. But I'm not sure if this way of viewing it helps...