Knowledge about arrays in java and about java Arrays
1,
2. array naming
1) int [] ages = new int [5];
2) int [] ages;
Ages = new int [5];
3) int [] ags = {1, 2, 3, 4, 5 };
4) int [] ags;
Ags = new int {1, 2, 4 };
Or
Int [] ags = new int {1, 2, 3, 4 };
3. java does not support cognominal arrays of different types.
4. Cyclic assignment of arrays in java
1 package dierge; 2 3 public class Shuzu {4 5 public static void main (String args []) {6 int [] ags = new int [5]; 7 int I; 8 for (I = 0; I <ags. length; I ++) {9 ags [I] = I; 10 System. out. println ("ags [" + I + "]:" + ags [I]); 11} 12 13 14 15} 16 17}
The output is as follows:
Ags [0] is: 0
Ags [1] is: 1
Ags [2] is: 2
Ags [3] is: 3
Ags [4] is: 4
5. initial values of various types of Arrays
The Code is as follows:
1 package dierge; 2 3 public class Shuzu {4 5 public static void main (String args []) {6 int [] ags = new int [1]; 7 System. out. println ("the default value of the int type array is:" + ags [0]); 8 boolean [] a = new boolean [1]; 9 System. out. println ("the default value of a boolean array is:" + a [0]); 10 byte [] B = new byte [1]; 11 System. out. println ("default value of byte type array:" + B [0]); 12 short [] c = new short [1]; 13 System. out. println ("the default value of the short Type array is:" + c [0]); 14 char [] d = new char [1]; 15 System. out. println ("the default value of the char array is:" + d [0]); 16 long [] e = new long [1]; 17 System. out. println ("the default value of the long type array is:" + e [0]); 18 float [] f = new float [1]; 19 System. out. println ("the default value of float Type array is:" + f [0]); 20 double [] g = new double [1]; 21 System. out. println ("the default value of the double type array is:" + g [0]); 22 23 24 25 26 27 28} 29 30}
The output is as follows:
The default value of the int type array is 0.
The default value of a boolean array is false.
The default value of the byte array is 0.
The default value of the short array is 0.
The default value of the char array is:
The default value of the long type array is 0.
The default value of a float array is 0.0.
The default value of an array of the double type is 0.0.