IndexOutOfBoundsException marks an invalid position in indexed data. Java checks array, string, and list accesses, preventing silent corruption, incorrect behavior, and security holes, but the exception still signals a bug that callers should prevent. section 5.2
Empty input
Calling charAt(0) before checking that a string is nonempty fails for an empty string. Check the input boundary before accessing the character. section 5.2
Prevent the common boundary-checking mistakes:
- Check before indexing, not after it. section 5.2
- Use index < length, not a reversed comparison; an index equal to length is invalid. section 5.2
