How to Handle java.lang.IndexOutOf BoundsException
The java.lang.IndexOutOfBoundsException in Java is thrown when an index used in arrays, lists, or strings is not valid. A valid index must be a number from 0 up to one less than the total number of items. For example, in a list of 3 items, the valid indices are 0, 1, and 2. Here’s a quick example: The error message you’d get would look something like this: Here are some other common ways the IndexOutOfBoundsException might be thrown.