"StackOverflow Good question" Converts an array to a list

Source: Internet
Author: User

problemSuppose there are arrays
Element[]Array= {New Element(1),New Element(2),New Element(3)};
How do you convert it to arraylist<element> ArrayList?

Essence Answer
arrays   asList   array   Arrays.aslist(new Element (1), new Element (2), new Element (3))
However, there are some pits to be aware of:1. The list to be generated is fixed length. In other words, if you do add or remove to it, it will throw unsupportedoperationexception. 2, if you modify the value of the array, the corresponding value in the list will also change!
If you want to avoid these two pits, use this method instead
Collections.AddAll(ArrayList,Array);
StackOverflow:Http://stackoverflow.com/questions/157944/how-to-create-arraylist-arraylistt-from-array-t


Column Introduction: very like StackOverflow, can always find a solution to the problem of incurable diseases. Accidentally found that the site has a list of heat. So select some of the more hot questions, read all the answers to each question, and then sort them out in your own understanding. I hope that the discussion above will be presented to you in a more streamlined and appropriate way. if you want to reprint, please specify the original address Http://blog.csdn.net/lizeyang

"StackOverflow Good question" Converts an array to a list

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.