Arrays in Java are reference types
The elements of an array can be basic types or references Type, clarifying the type of array elements can help us understand the default initialization of array elements
The default initialization value of one-dimensional array elements is divided into There are two types, the elements are basic data types and reference data types
##Now we test the following code to deepen our understanding
public class Test {
public static void main(String[] args) {
char[] a = new char[2];
if(a[0] == 0) {
System.out.println("这是判断0的" + a[0] + "测试!");
}
if(a[0] == '0') {
System.out.println("这是判断字符'0'的" + a[0] + "测试!");
}
}
}
Through the results we found The value of a[0] is judged to be 0 instead of the character '0'. When printed, a[0] is actually a null character (this is not a space!!!)
2. The array elements are reference types When
3. Two-dimensional array
is divided into two situations (the writing format of the following two situations is represented by int, and int can be replaced by other data types)
1 . int[][] arr = new int[2][2]
The above is the detailed content of Explanation on how to determine the default initialization value of Java one-dimensional array and two-dimensional array elements. For more information, please follow other related articles on the PHP Chinese website!