Systems | Development | Analytics | API | Testing

April 2024

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.

How to Fix Unterminated String Literals

Imagine you want to leave a note for someone. You write the message on a piece of paper and put it in an envelope. The envelope around your note keeps the message contained and separate from other things. It's the same idea with terminating string literals. A string literal is like the note you wrote, while terminating it is like sealing the envelope. Here's an example: The phrase "Hello, world!" is the string literal, while the double quotation marks tell the computer where the string begins and ends.