As if we pass predefined list to the new ArrayList constructor it will SHALLOW-COPY that list which means reference to that list , so if we modify the new list ,the changes should also tends to modify at the old list .but in this programme it isnot the case .... WHY?
public class testArrayList {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
List<Integer> list2 = new ArrayList<>(list);
list.add(3);
System.out.println(list2.get(2));
}
}
It is giving me out of bound exception.. WHY?