1.
2. Naming method of array
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,3,4};
or
int[]ags=new int{1,2,3,4};
3. Java does not support different types of duplicate arrays
4. Loop assignment of arrays in java
package dierge; public class Shuzu { public static void main(String args[]){ int[]ags=new int[5]; int i; for(i=0;i<ags.length;i++){ ags[i]=i; System.out.println("ags["+i+"] is: "+ags[i]); } }}The printing results are as follows:
ags[0] is: 0
ags[1] is: 1
ags[2] is: 2
ags[3] is: 3
ags[4] is: 4
5. The initial value of arrays of various types
The code is as follows:
package dieerge;public class Shuzu { public static void main(String args[]){ int[]ags=new int[1]; System.out.println("the default value of array of type is: "+ags[0]); boolean[]a=new boolean[1]; System.out.println("the default value of array of type is: "+a[0]); byte[]b=new byte[1]; System.out.println("the default value of array of type is: "+b[0]); short[]c=new short[1]; System.out.println("short type array default value is: "+c[0]); char[]d=new char[1]; System.out.println(""char type array default value is: "+d[0]); long[]e=new long[1]; System.out.println(""long type array default value is: "+e[0]); float[]f=new float[1]; System.out.println(""f=new float[1]; System.out.println(""f"f=new float[1]); }}The printing results are as follows:
The default value of an array of int type is: 0
The default value of boolean type array is: false
The default value of byte-type array is: 0
The default value of short type array is: 0
The default value of a char type array is:
The default value of long-type array is: 0
The default value of float type array is: 0.0
The default value of double type array is: 0.0
The above summary of related knowledge about arrays in Java (recommended) is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.