18

How do I convert String Array to Array List:

String[] to ArrayList<String>

1

5 Answers 5

5

Try this:

String [] strings = new String [] {"stack", "overflow" };
List<String> stringList = new ArrayList<String>(Arrays.asList(strings)); 
3

Try this one

private ArrayList<String> list = new ArrayList<String>();
list.clear();

for(int i=0;i<StringArray.length;i++)
{
    list.add(StringArray[i]);
}
0
0

Try this..

String[] arr = { "40", "50", "60", "70", "80", "90", "100", };

ArrayList<String> arr_list = new ArrayList<String>();

for (int i = 0; i < arr.length; i++)
    arr_list.add(arr[i]);

or

ArrayList<String> arr_list = new ArrayList<String>(Arrays.asList(arr)); 
0

You can do

  • Use the Arrays.asList() method

    List<String> list = Arrays.asList(strings);
    
  • Create a new ArrayList and copy the elements of the array (not recommended)

    List<String> list = new ArrayList<String>();
    
    for (String str : strings)
    {
        list.add(str);
    }
    

Hope this helps.

0

Try this:

String[] words = {"ace", "boom", "crew", "dog", "eon"};  

List<String> wordList = Arrays.asList(words);  

for (String e : wordList)  
{  
    System.out.println(e);  
}