package com.wuming.struct; public class Demo09 { public static void main(String[] args) { int[] a={1,2,3,4,5,6,7,8}; for (int i = 0; i <=a.length; i++) {//=去掉,下标越界,数组下标为[0,length-1] System.out.println(a[i]); } } }
1
2
3
4
5
6
7
8
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at com.wuming.struct.Demo09.main(Demo09.java:7)
小结:
1.数组是相同数据类型的有序集合
2.数组也是对象,相对于对象的成员变量
3.数组长度不可变,越界报ArrayIndexOutOfBoundsException