导航菜单
首页 >  关于java中Index out of bounds经典错误  > Array Index Out Of Bounds Exception in Java

Array Index Out Of Bounds Exception in Java

Java supports the creation and manipulation of arrays as a data structure. The index of an array is an integer value that has value in the interval [0, n-1], where n is the size of the array. If a request for a negative or an index greater than or equal to the size of the array is made, then the JAVA throws an ArrayIndexOutOfBounds Exception. This is unlike C/C++, where no index of the bound check is done.

The ArrayIndexOutOfBoundsException is a Runtime Exception thrown only at runtime. The Java Compiler does not check for this error during the compilation of a program.

Java

// A Common cause of index out of boundpublic class NewClass2 {    public static void main(String[] args)    {        int ar[] = { 1, 2, 3, 4, 5 };        for (int i = 0; i

相关推荐: