3 ms·
Yes, ArrayLists are array-backed, but Arrays.asList instantiates a List and does not instantiate an array.
by thfuran 3y ago
Yes, ArrayLists are array-backed, but Arrays.asList instantiates a List and does not instantiate an array.
- tialaramex 3y agoAs I explained, List is an interface. You can't instantiate it, values are instances of types not interfaces. All that return type is telling you is, surprise, asList promises what you're getting implements the List interface. See if you can guess how you can implement the List interface using an Array. Still struggling, here's the one line of a typical implementation: return new Arrays.ArrayList(a);
- thfuran 3y agoYou should at least try to be correct if you're going to be so insufferable about it.