Java Learning Notes collection go to array---toArray ()

Source: Internet
Author: User

1  PackageP2;2 3 Importjava.util.ArrayList;4 Importjava.util.Arrays;5 Importjava.util.List;6 7  Public classToArray {8 9      Public Static voidMain (string[] args) {Ten          One         /* A * Set -to-go array - * The ToArray method in the collection interface is used.  - * Set-to-array: You can restrict the operation methods of elements in the collection, and do not allow additions or deletions to them the          *  -          *  - * The Toarrays method needs to pass in an array of the specified type.  - * How is the length defined?  + * If the length is less than the size of the collection, then the method creates an array of the same type and the same size as the collection.  - * If the length is greater than the size of the set, the method uses the specified array to store the elements in the collection, and the other location defaults to null + * So it is recommended that the last length be specified as the size of the collection.  A          */ at          -list<string> list =NewArraylist<string>(); -List.add ("ABC1"); -List.add ("ABC2"); -List.add ("Abc31"); -List.add ("ABC4"); in          -string[] arr = List.toarray (Newstring[list.size ()]); toSystem.out.println (arrays.tostring (arr));//results: [ABC1, ABC2, ABC31, ABC4] +  -  the     } *  $}

Java Learning Notes collection go to array---toArray ()

Related Article

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.