When we call ArrayList.add()
method, does it create a new object and add it to the list or does it adds the referenced object to the list?
For example: suppose we have two ArrayList
as follows:
ArrayList<ClassA> a1
and ArrayList<ClassA> a2
. If I run the code:
a2.add(a1.get(i))
will it create a new object and then add it to a2
or it will refer to the same object from two different lists?
It is not the copy of
Is Java pass by value or pass by reference question?
because I want to know the internal working of ArrayList.add()
method, that does it create an object copy of the parameter passed or not?