I have 2 ArrayLists in Java:
mProductList = new ArrayList<ProductSample>();
mProductList2 = new ArrayList<ProductSample>();
mProductList = productSampleList;
mProductList2 = productSampleList;
mProductList2 .remove(3);
The productSampleList has size 5. Why after this segment code is executed. mProductList has size 4?
Does we have any way to avoid this? I want the mProductList have size 5 as the same as productSampleList.
Thanks!
mProductList2 = productSampleList;
you reassignedmProductList2
to a different list. You have to grasp the concept of object references in Java. – Carreon