Arrays are objects. The parent class of the array is also Object, and each array implements the interfaces Cloneable and java.io.Serializable. The creation of arrays in Java uses the keyword new, although the format is different from the way ordinary classes are created.
But the type of the array is not visible to the programmer. But since arrays are also subclasses of Object, we can print out the type name of the data. (Recommended learning: java course)
// Java program to display class of <br/>// int array type<br/>public class Test<br/>{<br/> public static void main(String[] args)<br/> {<br/> int[] x = new int[3];<br/> System.out.println(x.getClass().getName());<br/> }<br/>}<br/>
Output:
[I<br/>
"[" means that this is an array, and it is one-dimensional, "I" indicates that the array elements are of type int.
You can also print other types of array names through this method:
Array type Corresponding class Name
int[] [I<br/>int[][] [[I<br/>double[] [D
double[][] [[D
short[] [S
byte[] [B
boolean[] [Z
The above is the detailed content of Are java arrays objects?. For more information, please follow other related articles on the PHP Chinese website!