public class Main {
public static void main(String[] args) {
int[] arrInt = new int[4];
for(int k : arrInt) {
System.out.print(k + " ");
}
System.out.println();
String[] arrString = new String[4];
for(String k : arrString) {
System.out.print(k + " ");
}
System.out.println();
double[] arrDouble = new double[4];
for(double k : arrDouble) {
System.out.print(k + " ");
}
System.out.println();
char[] arrChar = new char[4];
for(char k : arrChar) {
System.out.print(k);
System.out.print("-");
}
System.out.println();
boolean[] arrBoo = new boolean[4];
for(boolean k : arrBoo) {
System.out.print(k + " ");
}
}
}
运行结果:
0 0 0 0
null null null null
0.0 0.0 0.0 0.0
- - - -
false false false false
Java中,数组会默认初始化。其中,字符型默认初始化为“\u0000”,即为空格。