java.lang.ArrayIndexOutOfBoundsException:

ArrayIndexOutOfBoundsException is the Exception in a Programming language. You need to read carefully – Array Index Out Of Bounds Exception.

ArrayIndexOutOfBoundsException means when we try to access an Item in Array using that Index which is not in Array. In a Simple way, the Array length is Equal to or Shorter than the Index. so It is our range of that Array.

Here is the example of ArrayIndexOutOfBoundsException:

public class Example{
    public static void main(String[] args) {
        int arr[] = {1,2,3,4,5,6};
        System.out.println(arr[6]);
    }
}

Output

ArrayIndexOutOfBoundsException

In the Above Example, It is shown at line no.4, the Index is 6 where there is no value at 6 location in the array. (the size of the array is 6)

array index out of bounds exception (java.lang.arrayindexoutofboundsexception) means, In array there is no value in the given index.

For Debugging or solving, you can print the value using System.out.println() function

java.lang.arrayindexoutofboundsexception: 1

read also

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on whatsapp
WhatsApp
Share on reddit
Reddit
Share on telegram
Telegram

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top