Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException:

Posted: May 9, 2012 in Java

ArrayIndexOutofBoundsException:

It is the child class of Runtime Exception and it is unchecked, automatically raised by the JVM when ever we are trying to access an array element with out of Range index

Example:

public class Test {

public static void main(String[] args) {

int[] a = {10,20,30};

System.out.println(a[1]);

System.out.println(a[10]);  ———–> ArrayIndexOutofBoundsException bcoz we are accessing out of range index.

}}

Output:

20

Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 10

at com.clarity.test1.main(test1.java:91)

Leave a comment