Bounds checking validates that an index or indexed range lies within a data structure’s permitted limits. Java prevents out-of-range access with exceptions, but explicit checks still prevent empty-input failures, incorrect behavior, data corruption, and security holes. section 5.2
Avoid these common checking mistakes:
- Accessing an element before checking its index, such as calling charAt(0) on a possibly empty string. section 5.2
Prefer standard range checks
Custom array- and collection-like APIs can use Objects.checkIndex, Objects.checkFromToIndex, and Objects.checkFromIndexSize before accessing elements or ranges.

