int[] ary1 = new int[4]; // {0,0,0,0}
int[] ary2 = new int [] {1,2,3,4}; // {1,2,3,4}
int[] ary3 = {1,2,3,4}; // {1,2,3,4}
system.out.println(ary3.length);
for (int i=0; i<ary3.length; i++) {
system.out.println(ary3[i]);
}
以上會跑出:
4 //4個元素
1
2
3
4
2種寫法之間的差異: