How can I convert String[] to ArrayList<String>

Alexandre Hitchcox picture Alexandre Hitchcox · Apr 19, 2012 · Viewed 176.5k times · Source

Possible Duplicate:
Assigning an array to an ArrayList in Java

I need to convert a String[] to an ArrayList<String> and I don't know how

File dir = new File(Environment.getExternalStorageDirectory() + "/dir/");
String[] filesOrig = dir.list();

Basically I would like to transform filesOrig into an ArrayList.

Answer

Scott picture Scott · Apr 19, 2012

You can do the following:

String [] strings = new String [] {"1", "2" };
List<String> stringList = new ArrayList<String>(Arrays.asList(strings)); //new ArrayList is only needed if you absolutely need an ArrayList