Why does the java substring method work like this?

Viewed 940

This probably has a very obvious answer, but I just started learning Java and discovered this.

Say we have

String x = "apple";

Why is it that x.substring(5) returns "", an empty string while x.substring(6) throws an IndexOutOfBounds exception? Is there some kind of empty string that can be referenced appended to every string? Just not sure how it works.

Thanks!

3 Answers
Related