1)created a list 2)printed the list 2)created an array and changed the list to array 4)altered the first element of list 5)change is reflected in the list 6)BUT NOT IN THE ARRAY. THE SAME OLD VALUE IS PRINTED HERE. it should have been changed in the array, when i change the element in the list..???
it should have been changed in the array, when i change the element in the list..???
No. The array that gets created by toArray is independent of the original List. It contains the same objects, but it will not be updated if the List is updated (the List does not know about the array).
If you look at the source code of ArrayList.toArray you will see that there is no connection between the two.