String array to ArrayList

(1) with Arrays.asList() is efficient because it doesn't need to copy the content of the array. This method returns a List that is a "view" onto the array - a wrapper that makes the array look like a list. When you change an element in the list, the element in the original array is also changed. Note that the list is fixed size - if you try to add elements to the list, you'll get an exception. 


 (2)new ArrayList(Arrays.asList(myArray)); copies the content of the array to a new ArrayList. The copy is ofcourse independent of the array, and you can add, remove etc. elements as you like. 

(3) with Collections.addAll(myList, myStringArray); is essentially the same as Ernest's solution. 

If you only need read access to the array as if it is a List and you don't want to add or remove elements from the list, then use (1)solution. Otherwise use (2)(3) solution. 

你可能感兴趣的:(Access)