1.数组索引越界异常:
ArrayIndexOutOfBoundsException
当访问了不存在的索引时
异常︰即非正常情况,可以简单理解为程序运行过程中出现错误。
int[] arr1 = new int[3];
arr1[0] =1;
arr1[1] =2;
arr1[2] =3;
System.out.println(arr1[0]);
System.out.println(arr1[1]);
System.out.println(arr1[2]);
System.out.println(arr1[3]); //数组索引越界异常 ArrayIndexOutOfBoundsException
2.空指针异常
数组引用存储的值为null而非数组的地址值时
//需求演示空指针异常
int[] arr =new int[3];
arr[0] =11;
arr[1] =22;
arr[2] =33;
arr = null;
System.out.println(arr[0]); //NullPointerException
}
}