packageJava base 04_ one-dimensional array;import java.util.Arrays;
* Arrays: This is a built-in Java class that handles manipulating, sorting, finding, copying, filling, and matching strings */
public class ArraysDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String[] array= {"Sung river"."Li Gui"."Wu song"."Lin".Sun Er Niang."Lu Zhishen"};
		int[] array2= {2.3.15.63.84.6.24.84.7.68.9.5};
		int[] array3= {2.3.15.63.84.6.24.84.7.68.9.5};
	  // Sort the array ascending
		System.out.println("======== Sort the array ========");
		System.out.println("Array length: array.length:"+array.length);/ / 6
		Arrays.sort(array);// Generally, strings are not sorted.
		for(int i=0; i<array.length; i++) { System.out.print(array[i]+",");// sort by ASCII code: Sun Erniang, Song Jiang, Li GUI, Lin Chong, Wu Song, Lu Zhishen,
		}
		System.out.println();
		Arrays.sort(array2);
		for(int i=0; i<array2.length; i++) { System.out.print(array2[i]+",");/ / prioritize: basic class 2,3,5,6,7,9,15,24,63,68,84,84,
		}
		System.out.println();
		System.out.println("======== copy the array ========");
       /*copyof(int[] original,int newLength) * first argument original: is the array to copy * second argument newLength: the length to copy (specify the length of the new array to copy) */
		int[] array_2=Arrays.copyOf(array2, array2.length);
		for(int i=0; i<array_2.length; i++) { System.out.print(array_2[i]+",");/ / 2,3,5,6,7,9,15,24,63,68,84,84,
		}
		System.out.println();
		System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
        /* * copyofRange(int original,int from,int to) * Copies the specified range of the specified array to a new array * Third argument: The end position of the array to be copied, represented by the index value */
		int[] array_3=Arrays.copyOfRange(array3, 1.3);
		for(int i=0; i<array_3.length; i++) { System.out.print(array_3[i]+",");/ / 3, 15,
		}
		System.out.println();
		System.out.println("======== array comparison ========");
		/* * string is an array of characters * equals(int[] a,int[] a2) * Returns true if two arrays of int are equal to each other. In fact, the address values of the two arrays are compared first. If they are not equal, then the length is determined. If the lengths are equal, then each element is compared
		boolean flag=Arrays.equals(array2, array3);/ / not equal
		System.out.println(flag);//false
		System.out.println("======== array padding ========");
		/* * Fill (int[] a,int val) * assigns the specified int value to each element of the specified int array */
		Arrays.fill(array3, 99);
		for(int i=0; i<array3.length; i++) { System.out.print(array3[i]);/ / 999999999999999999999999
		}
		System.out.println();
		System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
		/* * Fill (int[] a,int fromIndex,int toIndex,int val) * assign the specified int value to each element in the specified range of the specified int array */
		Arrays.fill(array3, 0.4.22);
		for(int i=0; i<array3.length; i++) { System.out.print(array3[i]+",");/ / 22,22,22,22,99,99,99,99,99,99,99,99.
		}
		System.out.println();
		
		System.out.println("======== array lookup ========");
		/* * binarySerch(int[] a,int key) * uses binary search to search for the specified int array */
		int i=Arrays.binarySearch(array2, 15);//6 is its index value, and returns a negative number if the element is not in the array
		System.out.println(i);/ / 6
		System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
		/* * binarySearch(int[] a,int fromIndex,int toIndex,int key) * uses binarySearch to search the range of the specified int array to obtain the specified value */
		int j=Arrays.binarySearch(array2, 0.7.6);
		System.out.println(j);/ / 3}}Copy the code