What is the difference between these two styles of initialization :
List<String> list = new ArrayList<String>(Arrays.asList(arr));
and
List<String> list = Arrays.asList(arr);
One thing that I can make out is that in the latter case, we are not using the ArrayList class. But then, which class's object (list) are we creating here ?
The first creates a mutable List, the second is of fixed size. ArrayList is not the only implementation of List. Arrays.asList returns its own implementation which is of fixed size, i.e. individual elements can be updated but elements cannot be added or removed.
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