I am attempting to change the following array line into an ArrayList that will function the same way:
private String[] books = new String[5];
I changed it to this but it is not functioning properly:
private ArrayList<String>(Arrays.asList(books))
I thought this was how an ArrayList was created
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With