First array list:- ArrayList<Object> list1;
Second array list:- ArrayList<Object> list2;
Suppose I have filled list1 with some objects.
Now I copy some of objects from list1 using list2.add(list1[i]) and make change to object in list2 using list2[j].setA = something.
Will the corresponding value A of object in list1 change or not?
Actually I want the value A to be changed.
It will change. The lists contain only references to the objects*. So after adding some of the elements in
list1tolist2, the two lists will share references to the same physical objects.*In Java collections you can’t store primitive types such as
int, only their object counterparts (Integerin this case), always by reference.