Java is the future !: Programs(Moderate)
Showing posts with label Programs(Moderate). Show all posts
Showing posts with label Programs(Moderate). Show all posts

Sunday, April 24, 2011

How to convert a String array to ArrayList?

1.


2.


3.




Note: In the solution no 1 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.


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 only use solution no 1.

Source: JavaRanch