1. What is the difference between
I. New Arraylist<integer>(Arrays.aslist (IA)); List<Integer> list2 = Arrays.aslist (IA);
i. New arraylist<integer> (Arrays.aslist (IA))
- The new is an
ArrayList independent copy of the original one.
- Although you create the wrapper using
Arrays.asList , it's used only during the construction of the new and is ArrayList Garbage-col lected afterwards.
II. Arrays.aslist (IA)
- Array
ia and creates a wrapper that implements List<Integer> , which makes the original array as a list.
- Nothing was copied at all, with a single wrapper object is created.
- Operations on the list wrapper is propagated to the original array – if you shuffle the list wrapper, the original array is shuffled; If you overwrite a element, it gets overwritten in the original array, etc.
- Some list operations aren ' t allowed on the wrapper, like adding or removing elements from the List-no resize.
- List wrapper doesn ' t extend
ArrayList -- ArrayList S has their own, internal array, which they is able to resize.
2.
Java Q & A