Array operations in Java advanced, don't ask me why, the code interprets everything!

Source: Internet
Author: User

I'm not targeting someone, I'm talking about all the scum here!

 PackageCom.mi.array;Importjava.util.Arrays;/*** System.arraycopy (i, 0, J, 0, i.length); This copy overwrites the copy of the target array element * Array *@authorAdmin **/ Public classCopyarray { Public Static voidMain (string[] args) {int[] i =New int[7]; int[] J =New int[10]; Arrays.fill (i,47); Arrays.fill (J,99); System.out.println ("I=" +arrays.tostring (i)); System.out.println ("J=" +arrays.tostring (j)); //parameters (the original array, the starting position of the original array, the target array, the starting position of the target array, the number of elements that need to be copied)System.arraycopy (i, 0, J, 0, i.length); System.out.println ("J=" +arrays.tostring (j)); /*** Results * i= [99, 99, 99, 99, 99, 99, 99, 99, 99, 99] j= [+. j= [ +, A, a, a, a, a, ~ ~*/    }}
 PackageCom.mi.array;Importjava.util.Arrays;/*** * Array comparison/array element comparison *arrays.equals condition: 1, array length equal, 2, the value of the corresponding position of the array must be equal*/ Public classComparearray { Public Static voidMain (string[] args) {int[] a1=New int[10]; int[] a2=New int[10]; //Arrays.fill can also pass values to specific intervals of an array, such as Arrays.fill (a1,2,4 47); //Similarly, arrays.sort can order specific intervals, such as arrays.sort (a1,27);Arrays.fill (A1, 47); Arrays.fill (A2,47);            System.out.println (Arrays.equals (a1, a2)); }}
 PackageCom.mi.array;ImportJava.util.*;/*** Array sort/Find in sorted array *@authorAdmin **/ Public classStringsort { Public Static voidMain (string[] args) {int[] a1=New int[10]; //returns the index of the value in the array, or 1 if it does not exist        intIndex = Arrays.binarysearch (A1, 2); }}

Array operations in Java advanced, don't ask me why, the code interprets everything!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.