Yes, that link is where the api documentation gives this example ("emptiness".substring(9)). When i execute this in
IDE i do not get an exception (clearly the doc says that an exception will be thrown only if the index is
greater than the length of string. In this case length = 9 and so the string has the last char at index = 8. Without throwing an exception, substring() returns "" (empty string, not null). Totally weird in my opinion because at index = 9, we are out of bounds of "emptiness". I found another discussion on this topic at
this thread. But the explanation given there is not satisfactory. The documentation is correct, because it documents the exact behavior of this api (during execution). ie.... only index=10 throws an exception, but not index=9.
Never mind this post - i found the answer in another api i was reading. This is just a design characteristic of java strings. Following is from oracle doc.....
public int lastIndexOf(String str)
Returns the index within this string of the last occurrence of the specified substring. The last occurrence of the empty string "" is considered to occur at the index value this.length().