array Default value comparison chart
| Array type |
Default values for array elements |
| BYTE, short, int, long |
0 |
| float, double |
0.0 |
| Char |
' + ' |
| Boolean |
False |
| Object.type |
Null |
Related Operations for arrays:
1. Array length
Syntax format: array name. length
2. Array padding
Syntax format: Arrays.fill (array name, value) Arrays.fill (array name, start subscript, end subscript, value)
Note: When assigning to arrays using the Fill method of arrays, you can specify the starting position begin and end position end, which will only assign to the array elements in the following table for the [begin,end] interval.
3. Array replication
Syntax format: Arraycopy (array A, start copying subscript, copy to array B, start copy subscript, copy length)
4. Array comparison
Syntax format: arrays.equals (array 1, array 2) return value to Boolean type
5. Array sorting
Syntax format: Arrays.sort (Array)
6. Finding array elements
Syntax format: arrays.binarysearch (array) binary lookup operation
ImportJava.lang.reflect.Array;Importjava.util.Arrays; Public classJavaTest2ImplementsJavaTest1 { Public Static voidMain (string[] args) {int[][]a={{1,2,3},{4,8},{5,7,6}}; int[][]b={{1,2,3},{1,2,3,4},{12,12,1}}; int[]c={1,2,5,4,3}; int[]d=New int[5]; //traversing array a for(int[] is:a) { for(intI:is) {System.out.print (i+" "); } } //to sort the C arrayArrays.sort (c); for(inti = 0; i < c.length; i++) {System.out.print (C[i]+" "); } System.out.println (); //comparison of two arraysSystem.out.println (Arrays.equals (A, b)); //array for numeric lookupSystem.out.println (Arrays.binarysearch (C, 4)); //Array ReplicationSystem.arraycopy (c, 1, D, 1, 4); for(inti:d) {System.out.print (i+" "); } System.out.println (); //array paddingArrays.fill (d, 0, 1, 1); for(inti:d) {System.out.print (i+" "); } }}
Operation Result:
1 2 3 4 8 5 7 6 1 2 3 4 5 false2 3 4 5 1 2 3 4 5
Note: Some of these methods are valid only for one-dimensional arrays
Related knowledge of arrays