I am studing Java, i have simple Array linked to ArrayList, it is fixed size i can change values inside array or list without change length. So i tried to change all elements of the Array to see changes into ArrayList (it doesn't work). I saw that if i change single value into Array my list would change too (it works). If i change my List values into array wuold changed. If i change List or Array length would throw exception.
String[] nameListLinkedToArrayFixedSize = {"Jhonny","Joe","Jhoseph"};
List<String> nameListLinkedToArray = Arrays.asList(nameListLinkedToArrayFixedSize);
nameListLinkedToArrayFixedSize[1] = "J.Joe"; // this change my list
nameListLinkedToArrayFixedSize = new String[]{"ead","sda","eps"}; //change my array but non change my list
System.out.println(nameListLinkedToArray) // is same as first array why?
nameListLinkedToArray.set(2, "J.Jhoseph"); //[Jhonny, J.Joe, J.Jhoseph]
I need to understand how works linked arrays, i suppose this is not go well without point new array to new linked list?
Why single operation on array change list?
What is pointer of linked list after i change all element of array?
Why my list continues update old values of array?
Where to find specific documentation?
new String[]{"ead","sda","eps"}; //change my array but non change my list
No. That throws away your old array and makes a new array.nameListLinkedToArrayFixedSize
that points to an Array Object. You then create an ArrayList and that List internally points to the same Array Object. The List doesn't point to your variable, but the Array Object itself. Then you create another Array Object and have your variablenameListLinkedToArrayFixedSize
point to that new Object.