l Array:
Declare
l One dimensional array declaration:
n Int a1 [] = new int [5];
n int [] a1; a1 = new int [5]; // But can not int [5] A1 (((((((declared the array size can only be "=" right)
n Int TestArray []; testArray = new int [6] {1, 2, 3, 4, 5, 6}; // [] can not have SIZE
l Multidimensional array declaration:
n int [] [] A1 = {{1, 2}, {3, 4, 5}, {6, 7, 8, 9}};
l Require special attention:
n string [] s1 = new string [] {"a", "b", "c"}; string [] s1 = new string [] {'a', 'b', 'c'};
N char [] c1 = new char [] {'a', 'b', 'c'}; char [] c1 = new char [] {"a", "b", "c"};
Ø When the array is declared as char, {} can be 'a' (~ z), '0' (~ 9), 0 (~ 65535), '/ u0000' (~ '/ uffff))
Ø If the array is declared, if {'3', 'a'}, regardless of the shape, the print is all ANSI code, but pay attention to legitimacy (as above).
Ø If the array is declared for the first value, the initial value is "blank", {''} is legal, but {''} is not legal, at least there must be blank (but if String, then " "With" is legal).
can
l When you declare, you must specify a data type, and the elements in the same array must be the same.
l When the array is announced, [] must be in the back of the TYPE or name.
(int [] A1 [], A2 []; int [] A5, A6 []; int [] A7, A8 []; int [] A3, [] A4;)
l All array types are Implement from "Cloneable Interface", "Serializable Interface", so any array can be accepted by ASSIGN to Cloneable Type.
Cannot
l Primitive Array Types cannot be ASSIGNED (long args = integer args).
l The declaration size and the initial value cannot appear simultaneously, otherwise it will-time Error, but it is not available.
l The variable cannot be ASSIGN to two-dimensional arrays, and one-dimensional array should not be ASSIGN to two-dimensional arrays.
note
l Arrays will be initially do if Class-Level or Local will be init, and the content value is determined by TYPE.
The size of the array is myary.length, not myary.length (). Length does not have to declare or change.
The Index of the array is limited to byte, short, int, char four types of Type.
l Access range exceeds the array index range generating exception, for Runtime Exception is not Compile Exception
l byte [] Ary1, Ary2 []; // Ary2 is a two-dimensional array, be careful not to be. L float ary = new float [123]; // 不 合 合, 少括; Object ary = new float [123]; // legal
From: [Garfield's SCJP Read Note]