數據長度不可改變

數組的一旦初始化,長度不能改變,內容能夠改變。java

數組初始化爲null或者{}的時候,數組的長度都爲0,故而不能再被賦值,不然會報錯,下例註釋部分就會報錯數組

 

package test;

public class testArray {
	public static void main(String args[]){
		Integer a[]=new Integer[2];
		Integer b[]=null;
		Integer c[]={};
		a[0]=1;
//		b[0]=2;
//		c[0]=3;
		System.out.println(a[0]);
//		System.out.println(b[0]);
//		System.out.println(c[0]);
	}
	
}
相關文章
相關標籤/搜索