How To Convert Array To ArrayList

preview_player
Показать описание
Converting Array to ArrayList can be done very easily using existing Java library classes. Java 8 now allows you to convert to convert primitive array of int, long and double to ArrayList of List.
Рекомендации по теме
Комментарии
Автор

starts at 3:30, good explanation. thanks

sidshri
Автор

Second quibble (I will be watching more of these videos but still wanted to mention about this one)...your examples don't make use of anything you couldn't do with the original Array, as the enhanced for loop works just fine on Arrays as well of course.

If you do a modification of the second technique you show even for Arrays of objects, then you can do everything with the new List<whatever> that you get -- it is no longer just a view of the underlying array, and changes to it would not change the original array.
List<String> asAList = );
asAList.add("Woof");
asAList.remove(3);

In short, the two techniques you show are each very different from the other, if you use what I show they are more similar to each other (both create a new List that can have members added or removed).

jvsnyc
Автор

I mostly like this and will watch more of your videos. However, in the first part, ending about 3:00, you don't mention the major limitation of what we are doing here: you do have an ArrayList<> sort of, but you can not add any new elements to it, nor delete any elements from it -- it just allows you to access the underlying array as if it were an ArrayList<> -- well, except for ever adding any new elements or removing any. There are other good reasons to want to pretend it is an ArrayList<> of course, but those are two that you might think you get from this -- you don't.

jvsnyc