Sorry if the title is not clear.
Now in the rows the index starts at 0. So, for example:
Index 0 1 2 3 4
String H E L L O
In this case, the last index is 4.
If I try to do something like this:
System.out.println("hello".charAt(5));
He would throw an “Index Out Of Bounds Exception,” as it should.
However, if I try to run the following code:
System.out.println("hello".substring(5));
He works! I wrote a similar code, noticed this later and could not understand.
After all, the question is, as far as possible, we can achieve this index, shouldn't we? This allows us to write:
stringObj.substring(stringObj.length());
and that doesn’t look very safe, since stringObj.length () returns us an integer that is larger than the last index.
? , , ?