Objective
In Java, there are many well-packaged classes that can be used to manipulate arrays (sorting, copying, and so on), making arrays very convenient to use. This is the benefit of a high-level language.
code example-one-dimensional array
Packagetest;Importjava.util.Arrays; Public classTest { Public Static voidMain (string[] args) {int[]a = {1, 3, 5, 2, 4, 6}; //convert an array to a string outputSystem.out.println (Arrays.tostring (a));/*//Sort the array after output arrays.sort (a); System.out.println (Arrays.tostring (a)); Finds the subscript System.out.println of an element in an array (Arrays.binarysearch (A, 1)); System.out.println (Arrays.binarysearch (A, 5)); Copy an array of int []b = arrays.copyof (A, a.length); System.out.println (arrays.tostring (b)); Sets all array elements to a value of Arrays.fill (b, 9); System.out.println (arrays.tostring (b)); Compare two arrays of System.out.println (Arrays.equals (A, b)); Arrays.fill (A, 9); System.out.println (Arrays.equals (A, b));*/ }}
code example-two-dimensional array
1 Packagetest;2 3 Importjava.util.Arrays;4 5 Public classTest {6 7 Public Static voidMain (string[] args) {8 9 //statically createdTen int[][]a = { One{1, 3, 5, 2, 4, 6}, A{2, 4, 6, 1, 3, 5} - }; - the //dynamically created - introw = 2; - intCol = 6; - int[][]B =New int[Row][col]; + - //convert an array to a string output + System.out.println (Arrays.deeptostring (a)); A System.out.println (arrays.deeptostring (b)); at - } -}
Run results
Slightly.
Summary
1. Be aware of the dynamic creation of the above two-dimensional array. The meaning of this code differs from that in C + +-C + + can only create a one-dimensional pointer array dynamically, and then a new one-dimensional array on the pointer element of each pointer array. Here is the direct new out of the two-dimensional array.
2. There are many convenient APIs that are not listed in detail, so consult the Java API manual when using it.
Array manipulation in Java