1,
2, the method of naming the 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 names array
4. Cyclic 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);}
}
Print the results 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 values of various types of arrays
The code is as follows:
Package dierge;
public class Shuzu {public
static void Main (String args[]) {
int[]ags=new int[1];
SYSTEM.OUT.PRINTLN (the default value for an array of int type is: "+ags[0]);
Boolean[]a=new boolean[1];
SYSTEM.OUT.PRINTLN ("The default value for the Boolean array is:" +a[0]);
Byte[]b=new byte[1];
SYSTEM.OUT.PRINTLN ("The default value of the byte array is:" +b[0]);
Short[]c=new short[1];
SYSTEM.OUT.PRINTLN (the default value for the "short type array is:" +c[0]);
Char[]d=new char[1];
SYSTEM.OUT.PRINTLN (the default value for the "char type array is:" +d[0]);
Long[]e=new long[1];
SYSTEM.OUT.PRINTLN (the default value of the "Long array is:" +e[0]);
Float[]f=new float[1];
SYSTEM.OUT.PRINTLN (the default value for the "float type array is:" +f[0]);
Double[]g=new double[1];
SYSTEM.OUT.PRINTLN (the default value for the "double array is:" +g[0]);
}
Print the results as follows:
The default value for an array of type int is: 0
The default value for a Boolean array is: false
The default value for the byte array is: 0
The default value for the short type array is: 0
The default values for the char type array are:
The default value for a long array is: 0
The default values for the float type array are: 0.0
The default values for the double array are: 0.0
Above this Java array of relevant knowledge of the summary (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.