数组越界异常,这是在开发中不能出现的,一旦出现就必须修改我们编写的代码,为什么会出现数组越界问题呢,首先我们看一下代码。
public static void main(String[] args) {
int[] arr = {1,2,3};
System.out.println(arr[3]);
}
创建数组,赋值3个元素,数组的索引就是0,1,2,没有3索引,因此我们不能访问数组中不存在的索引,程序运行后,将会抛出 ArrayIndexOutOfBoundsException 数组越界异常,这就是越界问题。