FAQ: java.lang.IndexOutOfBoundsException

java.lang.IndexOutOfBoundsException
as the name suggests Your code is accessing a memory block that hasn’t been assigned yet.

For E.g. : Let’s say we have an array of integers with 5 elements.
int Arr[5] = {1,2,3,4,5};

Now, if we try to print the element at 2nd position
System.out.println(Arr[1]); (0-based indexing)
The output would be 2

But similarly, If we try to print the 6th element of the Array.
System.out.println(Arr[5]);
The output would be java.lang.IndexOutOfBoundsException
since we are trying to access the 6th element.

So, if you are getting this error, please check that your code is working in defined bounds and not accessing out of scope declared memory,