标签:
(注:int[] array = new int[0];是合法的)
3.多维数组,具可看做一维数组
public static void main(String[] args) {
int[][] a = new int[4][5];
a[0] = new int[2];//注意每个二维的维度都不相等
a[1] = new int[3];
a[2] = new int[4];
a[3] = new int[5];
a[0][0] = 5;
a[0][1] = 7;
for (int[] m : a) {
for (int t : m) {
System.out.print(t);
System.out.print(" ");
}
System.out.println();
}
/* 下面代码会出错
* for(int i = 0; i < a.length ; i++){
for(int j = 0; j < a[3].length; i ++){
System.out.print(a[i][j]);
}
}*/
/*输出结果:
* 5 7
* 0 0 0
* 0 0 0 0
* 0 0 0 0 0
*/
}
Arrays are special objects in java, they have a simple attribute named length
which
is final
.
There is no "class definition" of an array (you can‘t find it in any .class file), they‘re a part of the language itself.
It‘s "special" basically, with its own bytecode instruction: arraylength
. So
this method:
int x = args.length;
}
is compiled into bytecode like this:
public static void main(java.lang.String[]);
Code:
0: aload_0
1: arraylength
2: istore_1
3: return
通过javap更好的说明了数组的length属性,其实是一个单独的二进制指令:arraylength
标签:
原文地址:http://blog.csdn.net/woliuyunyicai/article/details/45025367