Operation of an array of Java

Source: Internet
Author: User

1 copy Array
Array full copy
Array positioning copy
2 Determine if the array is equal (each element corresponds to equality)
3 Mutual transformation of arrays and sets

1 Importjava.util.Arrays;2 Importjava.util.List;3 4 /*5 1 Copy Array6 Array Full copy7 Array Positioning copy8 2 Determine if the array is equal (each element corresponds to equality)9 3 Mutual transformation of arrays and setsTen  * */ One  A  Public classDemo2 { -      Public Static voidMain (string[] args) { -Integer[] arr = {1, 2, 3, 4}; the         //array copy function (the array to be copied, the new array length after the copy) -integer[] arr2 = arrays.copyof (arr, 4); -SYSTEM.OUT.PRINTLN ("Array after arr2 copy:" +arrays.tostring (ARR2)); -         //Locating copies +integer[] Arr3 = Arrays.copyofrange (arr, 1, 3);//copy 1th to third element, left open right closed, that is, the number of copies is 2,3 -SYSTEM.OUT.PRINTLN ("Array after partial copy of ARR3:" +arrays.tostring (ARR3)); +         //To determine the equality of arrays ASystem.out.println ("Compare arr and arr2 are the same:" +arrays.equals (arr, arr2)); at         //Convert an array to a list collection -list<integer> list =arrays.aslist (arr); -System.out.println ("Elements of the collection:" +list); -          -     } -}

Operation Result:

Operation of an array of Java

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.