Java array:
One-dimensional data Declaration: int A []; int [] A; the length of the array cannot be specified during the Declaration, that is, the number of elements in the array.
Create an array: Use new in Java to create an array: array name = type of the new array element [number of array elements];
Initialization:
1. Dynamic initialization: the array definition is separated from the operations for allocating space and assigning values to arrays;
2. Static initialization: when defining numbers, allocate space for array elements and assign values;
3. Default initialization: The array is a reference type, and its elements are equivalent to member variables of the class. Therefore, after the array is allocated space, each element is also initialized by the hermit according to the rules of the member variables.
Example: (Dynamic initialization)
Public class Array {</P> <p> Public static void main (string ARGs []) {<br/> // data declaration, creation, initialize <br/> date days []; // declare <br/> days = new date [3]; // create </P> <p> days [0] = new date (, 5); // initialization <br/> days [1] = new date, 31); <br/> days [2] = new date (2007,4, 4 ); <br/>}< br/> // </P> <p >}</P> <p>
Example: (static initialization)
Int A [] = {0, 1, 2 };
Example: (default initialization)
IntA [] =New Int[5];
Declare and create arrays at the same time:
Int A [] = new int [5];
String s [] = new string [] {"ZER "};
Javascript array:
VaR arr = new array (); <br/> // directly declare an array object <br/> var arr1 = new array (20 ); <br/> // declare an array object and initialize the array. Set the array size to 20. <br/> var arr2 = new array ("red ", "Blue", "green"); <br/> // declare an array and set the initial value for the Array Using parameters <br/> var arr3 = ["red ", "Blue", "green"]; <br/> // you can use a pair of [] to initialize the array.