Changing an Array to an ArrayList

This question already has an answer here:

  • Create ArrayList from array 32 answers

  • You need to create it like this:

    private ArrayList<String> booksList = new ArrayList<String>(Arrays.asList(books));
    

    new ArrayList<String>(Arrays.asList(books)) is the part which is turning your array into an ArrayList .

    You could also do:

    private List<String> booksList = Arrays.asList(books);
    

    If the fact that it is an ArrayList doesn't matter.


    Answered here

    new ArrayList<Element>(Arrays.asList(array))
    

    *** new

    链接地址: http://www.djcxy.com/p/17642.html

    上一篇: 将数组放入ArrayList中

    下一篇: 将数组更改为ArrayList