Stackoverflow: convert an array to List and stackoverflowlist.
ProblemSuppose there is an array
Element[] array = {new Element(1),new Element(2),new Element(3)};
How to convert it to ArrayList <Element> arraylist?
Excellent answer
Arrays. asList (array) or
Arrays. asList (new Element (1), new Element (2), new Element (3 ))
However, some pitfalls should be noted: 1. The list generated in this way is fixed length. That is to say, if you add or remove it, UnsupportedOperationException will be thrown. 2. If you modify the array value, the corresponding value in the list will also change!
If you want to avoid these two pitfalls, use this method instead.
Collections.addAll(arraylist, array);
Original Site of stackoverflow:Http://stackoverflow.com/questions/157944/how-to-create-arraylist-arraylistt-from-array-t
Column introduction:
I like stackoverflow very much and can always find a solution to the problem. The website has a popularity list. So I selected some hot questions, read all the answers to each question, and sort them out based on my own understanding. We hope that the above discussion will be presented in a more streamlined and appropriate manner.
If you need to reprint, please specify the original address
Http://blog.csdn.net/lizeyang
Converting list to String Array
For (int I = 0; I <s. length; I ++) {// Add the items in the s array to the list.
List. add (s [I]);
}
List. toArray (); // you can directly convert a list to an array. I cannot remember the method name clearly. You can check the api
Microsoft visual studio, I only defined a very large array a [116674]. Why is stackoverflowexception?
Stack Overflow ~
Try ArrayList ~