Arrays
Arrays in Java are Objects
-
This is why arrays are initialized using
new
keyword -
For each array type, there exists a corresponding class.
-
So there is a class for int[], for float[], double[] etc.
-
These classes are the part of java language and not available to the programmer level
-
To know the class of any array
// Here x is the name of the array. Sys
-
Corresponding class names for some array types
Array typeCorresponding Class Name
int[] [I
int[][] [[I
double[] [D
double[][] [[D
short[] [S
byte[] [B
boolean[] [Z
[ for single dimension [[ for two-dimensional
- Every array type implements Serializable and Cloneable.
- Arrays can be assigned to variables of type Object — Upcasting.
- All methods of Object class can be invoked on an array
Arrays
Methods
Arrays.sort(arr)
Arrays.fill(arr,0)
: Fills all elements of an array with the passed value.